【问题标题】:How to display different strings on button click如何在按钮单击时显示不同的字符串
【发布时间】:2014-08-10 02:46:45
【问题描述】:

我想做的是向我的应用程序添加多种语言,但我找不到这样做的方法。我已经创建了一个名为 values-es 的文件夹,并将它的 strings.xml 文件翻译成西班牙语。因此,当我单击菜单 > 语言 > 西班牙语时,我希望应用程序更改为西班牙语。那可能吗?如果是的话,如果你能帮助我,我将不胜感激:)

这只是我的 java 的一部分:

case id.language:

        CharSequence colors[] = new CharSequence[] {"English", "Spanish", "Portuguese", "Russian"};


        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Language");

        builder.setItems(colors, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int item) {
                if(item == 0) {

                } else if(item == 1) {

                } else if(item == 2) {

                } else if(item == 3) {

                }
            }

        });
        builder.show();
        break;  

【问题讨论】:

    标签: java android eclipse dialog


    【解决方案1】:

    请试试这个

        Resources res = context.getResources();
        // Change locale settings in the app.
        DisplayMetrics dm = res.getDisplayMetrics();
        android.content.res.Configuration conf = res.getConfiguration();
        conf.locale = new Locale(language_code.toLowerCase());
        res.updateConfiguration(conf, dm);
    

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 2018-11-06
      • 2020-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-25
      相关资源
      最近更新 更多