java - 为 fragment 中的 TextView 设置语言环境

标签 java android android-fragments textview locale

我想为单个 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/

相关文章:

php - 如何将图像保存到 android 中的 SQLite 数据库?

java - JDK 8 中的 PermGen 消除

jquery - android浏览器手机网页模态窗口

java - Springboot 和 Ehcache - MultiCacheException

使用 findViewById 初始化对象后直接出现 java.lang.NullPointerException

android - 在运行时在已经膨胀的层次结构中添加 View /布局?

android - 如何告诉我的自定义 FragmentPagerAdapter 停止销毁我的 Fragment?

android - 从 viewPager 中的 fragment 隐藏父 fragment

java - 如何从线程更新黑莓 UI 项目?

java - 如何使用 Java 打印 Worklight 属性