如何在android中的strings.xml中的警报对话框中添加项目名称

发布于 2024-11-24 17:55:25 字数 354 浏览 0 评论 0原文

在我的应用程序中,当我单击按钮时,我将打开警报对话框生成器。我的代码如下

AlertDialog.Builder builder = new AlertDialog.Builder(BannerImage.this);
final CharSequence[] items = {"Skip", "video", "Audio", "Games"};
builder.setTitle(" Funn ");

,而不是在此处键入项目名称,我想从 R.strings.xml 文件添加这些名称 但它显示了一些错误,当我的用户更改区域设置时,我想显示不同的语言,我需要这样做。如何添加字符串文件中的值...

in my app when i click a button i am opening an Alert Dialog builder. My code is as follows

AlertDialog.Builder builder = new AlertDialog.Builder(BannerImage.this);
final CharSequence[] items = {"Skip", "video", "Audio", "Games"};
builder.setTitle(" Funn ");

here instead of typing the items name here i want to add those name from R.strings.xml file
but it shows some errors, as my user changes the locale i want to show different language for that i need to do like this. How to add the values from strings file...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的憧憬 2024-12-01 17:55:25
final CharSequence[] items = {getString(R.string.skip), getString(R.string.video), getString(R.string.audio), getString(R.string.games)};

然后创建 string.xml 文件

<resources>
<string name="skip">skip</string>
<string name="video">Video</string>
<string name="audio">Audio</string>
<string name="games">Games</string>
</resources>


<resources>
<string name="skip">Siguiente</string>
<string name="video">Video</string>
<string name="audio">Audio</string>
<string name="games">Juegos</string>
</resources>
final CharSequence[] items = {getString(R.string.skip), getString(R.string.video), getString(R.string.audio), getString(R.string.games)};

and then create your string.xml file

<resources>
<string name="skip">skip</string>
<string name="video">Video</string>
<string name="audio">Audio</string>
<string name="games">Games</string>
</resources>


<resources>
<string name="skip">Siguiente</string>
<string name="video">Video</string>
<string name="audio">Audio</string>
<string name="games">Juegos</string>
</resources>
聆听风音 2024-12-01 17:55:25

continue

You neeed to create seperate resource files for each language. E.G

  1. res/values/strings.xml - For all English strings that the application uses.
  2. res/values-fr/strings.xml - For all French strings that the application uses.
  3. res/values-ja/strings.xml - For all Japanese strings that the application uses.

Please read the Localization article for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文