如何显示在Android的南印度语 [英] How to display south Indian languages in Android

查看:156
本文介绍了如何显示在Android的南印度语的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,显示多国语言特别卡纳达语和泰卢固语一个文本 我正在开发与最低要求的API 14(4.0)

I have a requirement to display one text in multiple languages especially Kannada and Telugu I am developing with minimum required API 14 (4.0)

三江源

推荐答案

试试这个...

我在这里分享整个应用程序code。

I shared here the whole application code.

项目结构

activity_main_activity1.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2b579a"
android:orientation="vertical"
tools:context=".MainActivity1" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/kannada"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="start"
        android:text="@string/kannada"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <Button
        android:id="@+id/telugu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="end"
        android:text="@string/telugu"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <Button
        android:id="@+id/english"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="end"
        android:text="@string/english"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />
</LinearLayout>

<TextView
    android:id="@+id/news"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:text="@string/note"
    android:textColor="#FFFFFF"
    android:textSize="20sp" />

 </LinearLayout>

价值/ strings.xml中

值-KN / strings.xml中

串卡纳​​达语。

值-TE / strings.xml中

设置字体

下载字体<一href="https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&sqi=2&ved=0CDIQFjAC&url=http://nelavankaonline.com/?page_id=64&ei=5zQpU8z_KYS_rge8nIGQCQ&usg=AFQjCNF1GONreMOXvyp4tZ6ys1V8dPPXXw&bvm=bv.62922401,d.bmk&cad=rja">here.

MainActivity1.java

package com.hirecraft.stackoverflowtest;

import java.util.Locale;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity1 extends Activity {

/**
 * Declaration
 */
Button kannada, telugu, english;
String currentLanguage;
TextView news;
Typeface kannadaFont, teluguFont;

/**
 * This class describes all device configuration information
 * that can impact the resources the application retrieves. This
 * includes both user-specified configuration options (locale
 * and scaling) as well as device configurations (such as input
 * modes, screen size and screen orientation).
 */
Configuration config;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_activity1);

    /**
     * Initialization
     */
    currentLanguage = "";
    kannada = (Button) findViewById(R.id.kannada);
    telugu = (Button) findViewById(R.id.telugu);
    english = (Button) findViewById(R.id.english);

    news = (TextView) findViewById(R.id.news);

    /**
     * Initialize the fonts.
     */
    kannadaFont = Typeface.createFromAsset(getAssets(), "fonts/akshar.ttf");
    teluguFont = Typeface.createFromAsset(getAssets(), "fonts/gautami.ttf");

    /**
     * Event for Kannada
     */
    kannada.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            /**
             * "kn" is the localization code for our Kannada language.
             */
            currentLanguage = "kn";
            Locale locale = new Locale(currentLanguage);
            Locale.setDefault(locale);

            /**
             * Print the current language
             */
            System.out.println("My current language: "
                    + Locale.getDefault());


            config = new Configuration();
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config,
                    getBaseContext().getResources().getDisplayMetrics());

            news.setText(R.string.note);
            news.setTypeface(kannadaFont);
        }
    });


    telugu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            /**
             * "te" is the localization code for our Telugu language.
             */
            currentLanguage = "te";
            Locale locale = new Locale(currentLanguage);
            Locale.setDefault(locale);

            /**
             * Print the current language
             */
            System.out.println("My current language: "
                    + Locale.getDefault());

            config = new Configuration();
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config,
                    getBaseContext().getResources().getDisplayMetrics());

            news.setText(R.string.note);
            news.setTypeface(teluguFont);
        }
    });

    english.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            /**
             * "en" is the localization code for our default English language.
             */
            currentLanguage = "en";
            Locale locale = new Locale(currentLanguage);
            Locale.setDefault(locale);

            /**
             * Print the current language
             */
            System.out.println("My current language: "
                    + Locale.getDefault());

            config = new Configuration();
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config,
                                               getBaseContext().getResources().getDisplayMetrics());

            news.setText(R.string.note);
        }
    });
}
      }

AndroidManifest.xml中

屏幕快照:

1。默认的语言环境(英文)

2。卡纳达语

3。泰卢固文

编码快乐......

Happy coding.....

这篇关于如何显示在Android的南印度语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆