Android Gujrati和Hindi支持的应用程序 [英] Android Gujrati and Hindi Supported Application

查看:124
本文介绍了Android Gujrati和Hindi支持的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个支持印地语和古吉拉特语的应用程序.我正在从我的应用程序设置屏幕设置应用程序语言.就像我给用户一个选项,供用户在英语/印地语/古吉拉特语中选择一种语言.

I am creating an app which will support Hindi and Gujrati language. I am setting the application language from my app settings screen. like i given a option to user to select a language among English/Hindi/Gujrati.

我正在基于单选按钮选择设置区域设置.我将选择保存为持久性,并在此基础上更改应用程序中所有textviews的字体.

I am setting Locale on radio button selection basis. I am saving the selection in persistence and on that basis i am changing the typeface of all of textviews in my application.

一切正常,但是在应用运行之间它将语言更改为英语.假设我从设置屏幕中选择了印地文语言并运行我的应用程序.在10-15分钟后突然从值"目录中获取文本值,而不是从值-hi"中获取文本值.我真的不明白为什么要从默认值目录中获取它.我的应用程序动态数据运行良好.它出现在印地语中,甚至我的应用程序可绘制对象也可以正常工作,但问题仅在于它从值"目录中获取值.

EVERYTHING IS WORKING FINE.. but it changes the language to english in between the app running. suppose i selected the hindi language from my settings screen and running my app. suddenly after 10-15 min it takes text values from "values" directory, not from "values-hi". I really don't understand why its taking from default values directory. my applications dynamic data is working fine. its coming in hindi and even my app drawables are also working fine but the problem is only that it takes the values from "values" directory.

当用户从我的应用设置屏幕中选择语言时,将使用此方法.

THIS METHOD IS USED WHEN USER SELECT THE LANGUAGE FROM MY APP SETTINGS SCREEN.

public void setLocale(Context context, String lang) {

    Locale myLocale = new Locale(lang);
    Resources res = context.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);

}

此方法用于onecreate方法中的TEXTVIEW的SETTYPEFACE

THIS METHOD IS USED TO SETTYPEFACE OF TEXTVIEW IN ONCREATE METHOD

public static void setTypeface(TextView textView, Context context) {
    SharedPreferences sp = context.getSharedPreferences("language_selection", context.MODE_PRIVATE);
    String language = sp.getString("language", "English");

    if (language != null) {

        if (language.equalsIgnoreCase("Hindi")) {
            textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "gargi.ttf"));
        }
        if (language.equalsIgnoreCase("Gujrati")) {
            textView.setTypeface(Typeface.createFromAsset(context.getAssets(), "SHRUTI.TTF"));
        }
    }
}

推荐答案

尝试以这种方式设置您选择的Language:

Try to set your selected Language on this way:

Locale locale = new Locale("YourSelectedLang");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
    getBaseContext().getResources().getDisplayMetrics());

这篇关于Android Gujrati和Hindi支持的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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