【问题标题】:Android mutilanguage support安卓多语言支持
【发布时间】:2016-01-07 18:42:35
【问题描述】:

我已经看到要让应用程序支持诸如印地语之类的语言,那么您需要执行以下操作:- 1. 在 res 文件夹中,创建带有语言限定符的文件夹,其中将包含特定于语言的字符串文件。 2. 在您的布局文件中,不要对文本进行硬编码,而是使用诸如@string/hello_info 之类的变量。 3. 在 assets 下创建 fonts 文件夹,并在其中添加适当的 .ttf 文件。

但是,在某些地方,我还看到另外使用了以下内容。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TextView tv = (TextView) findViewById(R.id.textView);
    Typeface hindi = Typeface.createFromAsset(getAssets(), "fonts/mangle.ttf");
    tv.setTypeface(hindi);
}

现在是否需要,如果需要,在什么情况下?我只需要通过布局显示多语言文本。

另外,wrt 设备的区域设置,即假设例如在印度,区域设置将自动设置为该地区的适当值? 我如何通过设备或模拟器对此进行测试?我的设备只显示英语(英国)、英语(美国)、法国和西班牙。 提前致谢

【问题讨论】:

    标签: android locale multilingual


    【解决方案1】:

    是的,这是必需的,因为

    Typeface hindi = Typeface.createFromAsset(getAssets(), "fonts/mangle.ttf");
    tv.setTypeface(hindi);
    

    Typeface 使用该 ttf 字体文件为您的 textViews 文本设置任何类型的字体。可以是印地语、法国、西班牙等。

    【讨论】:

    • 感谢您的回复
    【解决方案2】:

    此代码仅用于使用您已添加到资产上的 .ttf 文件设置 custom font:

    TextView tv = (TextView) findViewById(R.id.textView);
        Typeface hindi = Typeface.createFromAsset(getAssets(), "fonts/mangle.ttf");
        tv.setTypeface(hindi);
    

    所以答案是肯定的。

    语言环境将自动设置为适当的值 那个地区?

    如果设备语言是那种语言,是的。

    语言文档: http://developer.android.com/training/basics/supporting-devices/languages.html

    本地化检查表: http://developer.android.com/distribute/tools/localization-checklist.html

    你可以设置语言:

    Locale locale = new Locale("en_US");
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        SettingActivity.this.getApplicationContext().getResources().updateConfiguration(config, null);
        langd.dismiss();
        Intent i = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(getBaseContext().getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
    

    设置后会清屏,可以看到效果。

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      相关资源
      最近更新 更多