【问题标题】:Change language Samsung S8+更改语言三星 S8+
【发布时间】:2019-09-17 12:15:51
【问题描述】:

我在 Samsung S8+ (android 9.0) 中面临更改语言问题。 我已将一个版本 .aab(“Android App Bundle 格式”)文件扩展名上传到 My Application 的 google play 商店。 现在我在 Play Store 上获得了这个应用程序,我可以轻松下载。 我已经在多台设备上安装了这个应用程序并且运行良好。

但是当我在三星 S8+ 上更改语言时,设备无法正常工作。 在我们的应用程序中,我们使用英语和日语两种语言,但为什么不能在我不知道的三星 S8+ 设备上运行,而另一台设备运行良好。

然后我在三星 S8+ 上安装了发行版 .apk 并运行。所以我想知道为什么 .aab 不起作用而 .apk 起作用。请给出你的答案。

请检查使用的代码

这是更改语言的基本方法

public void updateLocale() {
    String locality = MyApplication.getInstance().getSharedPref().getLanguage();
    if (locality != null && !locality.isEmpty() && locality.equals(Locale.ENGLISH.toString())) {
        Configuration configuration = getResources().getConfiguration();
        if (Build.VERSION.SDK_INT >= 17) {
            configuration.setLocale(new Locale(Locale.ENGLISH.toString()));
        } else {
            configuration.locale = new Locale(Locale.ENGLISH.toString());
        }
        getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
        onConfigurationChanged(configuration);
    } else {
        Configuration configuration = getResources().getConfiguration();
        if (Build.VERSION.SDK_INT >= 17) {
            configuration.setLocale(new Locale(Locale.JAPANESE.toString()));
        } else {
            configuration.locale = new Locale(Locale.JAPANESE.toString());
        }
        getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
        onConfigurationChanged(configuration);
    }
}

在更改语言屏幕上

Switch svChangeLang;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSharedPref = new SharedPreference(getApplicationContext());
    svChangeLang = (Switch) findViewById(R.id.sv_change_lang);

    String lanCode = mSharedPref.getLanguage();
    if (lanCode.equals(Locale.ENGLISH.toString()))
        svChangeLang.setChecked(true);
    else
        svChangeLang.setChecked(false);

    svChangeLang.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked)
                svChangeLang.setChecked(false);
            else
                svChangeLang.setChecked(true);
            mSharedPref.setLanguage(isChecked ? Locale.ENGLISH.toString() : 
            Locale.JAPANESE.toString());

            updateLocale();
        }
     });
   }

【问题讨论】:

    标签: java android android-studio sharedpreferences locale


    【解决方案1】:

    默认情况下,应用程序包无法做到这一点:Google Play 仅在设备选择的语言发生变化时下载资源。

    Solution First

    解决方案二:

    android {
    bundle {
        language {
    
            enableSplit = false
        }
    }
    

    }

    但第二种解决方案会增加应用程序 sie

    【讨论】:

      猜你喜欢
      • 2018-07-14
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 2018-06-26
      • 2019-03-09
      • 2018-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多