Android - 翻译菜单选项卡
有一种简单的方法可以使用值 strings.xml 翻译菜单选项卡的文本吗? 由于菜单文本是在 java 上设置的,我看不到有办法做到这一点。
如果没有,哪种方法更好?
已解决:
恢复字符串的方法:getString(R.string.tela_principal_menu_tab_um);
There is a simple way to translate menu tab's text using values strings.xml?
Since the menu text is set on java, i don't see a way to do that.
If there isn't, which is the better way to do that?
SOLVED:
Method to recover a string: getString(R.string.tela_principal_menu_tab_um);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
等往事风中吹2025-01-02 23:19:56
无论您的菜单是用 XML 还是 Java 构建的,您都应该能够使用 strings.xml。您可以使用 getString(R.string.string_name)
访问 Java 中的字符串。请参阅http://developer.android.com/guide/topics/resources/ string-resource.html,然后按照本地化说明进行操作:http://developer.android.com/guide/topics/resources/localization.html 用于您的字符串。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
虽然您无法在 strings.xml 中轻松完成此操作,但我经常在 xml 中使用菜单资源。它的工作原理如下:
在
res\
中创建一个名为menu
的文件夹。最初像这样设置 XML 文件
现在您可以将菜单添加到上面指定的空间中。
Groups
可以容纳多个Items
,或者您也可以只容纳Items
。每个都有自己的id
,因此您可以快速轻松地引用它。这是一个完整的示例..现在您可以简单地将其添加到您的代码中,如下所示:
最后,添加 onClicks:
希望这有帮助!
模糊逻辑
While you cannot do it in strings.xml as easily, I frequently use a menu resource in xml. It works like so:
Create a folder in
res\
namedmenu
.Set up the XML file initially like this
Now you can add your menu into the space indicated above.
Groups
can hold multipleItems
, or you can just holdItems
in there. Each has its ownid
so you can reference it quickly and easily. Here is a full sample..Now you can simply add it to your code like so:
Finally, you add the onClicks:
Hope this helps!
FuzzicalLogic