在Fragment中为文本视图设置区域设置

4

我想为单个文本视图设置区域设置。这意味着只有该文本视图将以另一种语言显示(在我的例子中是法语),但不幸的是它没有起作用。虽然我没有收到错误,但什么也没有发生。

 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);

我在普通的活动中尝试过这样做,结果完全没有问题。

你找到解决方案了吗?我陷入了和你一样的困境。这种方法在片段上不起作用。 - Shubham Nanche
2个回答

2
你可以使用 String.format()Locale.FRENCH 来本地化 TextView 的文本。 例子
String txtFrench = String.format(Locale.FRENCH, "%s", item.getFrenchName());
mFrenchTextView.setText(txtFrench);

0

但我在一个活动中完成了它,并且只翻译了那个TextView,它可以正常工作。使用以下代码: Locale locale = new Locale("fr"); maintext.setTextLocale(locale); - Metalloid66

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接