How can I change language of my application(如何更改应用程序的语言)
问题描述
可能重复:
在 Android 中以编程方式更改语言
我是 Android 新手.在我的应用程序中,用户可以从三种语言中选择一种语言.根据用户选择的语言,应该改变整个应用程序的语言.我该怎么做?
I am new to Android. In my application user can select a language from three languages. Based on the language selected by user, the entire application's language should be change. How can I do this?
推荐答案
使用它以编程方式更改语言:
Use this to change the language programmatically:
Locale locale = new Locale("en_US");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);
写下该语言的国家代码来代替您想要的任何语言的 "en_US"
.例如,对于日语,ja_JP
;对于阿拉伯语,ar
.检查 此链接 获取列表.
Write the country code of the language in place of "en_US"
for whatever language you want. For example, for Japanese, ja_JP
; for Arabic, ar
. Check this link for a list.
在 res/values-ja
中创建一个文件夹用于日语或 res/values-ar
用于阿拉伯语..
And make a folder in res/values-ja
for Japanese or res/values-ar
for Arabic..
并制作一个 string.xml
文件,并在布局上放置您想要的任何语言.它将从 values 文件夹中获取默认语言,否则如果您需要手动获取,它将从您的外部文件夹 values-ar
等中获取.
And make a string.xml
file, and put whatever languages you want on your layout. It will fetch the default language from values folder otherwise if you want it manually, then it will fetch from your external folder values-ar
, etc.
res/values-ar
的例子,用于阿拉伯语:
An example of res/values-ar
for Arabic:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="label">حسب</string>
<string name="name">بحث</string>
<string name="search">بحث :</string>
</resource>
这篇关于如何更改应用程序的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改应用程序的语言


基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01