我想为单个 TextView 设置语言环境。这意味着只有 textview 将以另一种语言显示(在我的示例中为法语),但不幸的是它不起作用。虽然我没有收到错误,但没有任何 react 。
Locale locale = new Locale("fr");
maintext.setTextLocale(locale);
tried updating confguirations , same thing . Nothing changes .
Locale locale = new Locale("fr");
Configuration config = new Configuration();
config.locale = locale;
getActivity().getResources().updateConfiguration(config,
getActivity().getResources().getDisplayMetrics());
maintext.setTextLocale(locale);
我尝试在正常 Activity 中这样做,并且效果很好。
最佳答案
您可以使用 String.format()
与 Locale.FRENCH
本地化该 TextView 的文本。
示例
String txtFrench = String.format(Locale.FRENCH, "%s", item.getFrenchName());
mFrenchTextView.setText(txtFrench);
关于java - 为 fragment 中的 TextView 设置语言环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31390979/