我正在编写支持多语言的应用程序,并且当我更改语言环境活动时,会重新创建,并且某些字段或组件不会通过某些设备的语言环境更改值。
这是我的代码:
public class BaseActivity extends AppCompatActivity implements BaseNavigator {
@Override
public void onLanguageChanged(String language) {
alertDialog.hide();
Resources resources = getBaseContext().getResources();
Configuration configuration = resources.getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
configuration.setLocale(Locale.forLanguageTag(language));
}
resources.updateConfiguration(configuration, getBaseContext().getResources().getDisplayMetrics());
Log.d("Language: ", "changeLanguage: " + language);
recreate();
}
public void showDialogView() {
AlertDialog.Builder addBuilder = new AlertDialog.Builder(this);
addBuilder.setView(languageDialogViewBinding.getRoot());
alertDialog = addBuilder.create();
alertDialog.show();
}
}
下面的我的TariffActivity类:
public class TariffActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
} else if (id == R.id.nav_language) {
setupChangeLanguageDialog();
showDialogView();
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
这是我的riff_item.xml代码:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/monthTextView"
android:text="@string/txt_money"
... />
<TextView
android:id="@+id/textView10"
android:text="@string/tariff_minutes"... />
<TextView
android:id="@+id/textView17"
android:text="@string/tariff_internet"
.../>
<TextView
android:id="@+id/textView18"
android:text="@string/tariff_sms"
... />
如果您能看到此图片,则一些俄语文字和其他英语文字
{{3}}