找到你要的答案

Q:I want to change my application language from default [duplicate]

Q:我想更改我的应用语言从默认[副本]

This question already has an answer here:

How to change language in android application. I am already using string.xml file to display a language.

How can I choose between two xml files on clicking on a radio button

这个问题在这里已经有了答案:

如何改变Android应用程序中的语言。我已经使用string.xml文件显示语言。

如何在单选按钮上选择两个xml文件之间的选择

answer1: 回答1:

for this you have to use localization concept.Do Google the Localization in android..... Create a new folder in res folder of your project for each language you want to implement in project. in that folder create a string.xml file

MyProject/
res/
   values/<-----------this is default folder

   values-fr/ <-----------this folder is for French language(fr is iso code for french language you can check the iso codes for all languages on this link http://www.w3schools.com/tags/ref_language_codes.asp)

similarly create values folder for each language suppose you also have to implement urdu in your project then you will have to create another values folder for urdu likevalues-ur/ now you have three values folders

MyProject/
res/
   values  <------ default
   values-fr <----for french
   values-ur <----for urdu

now create a String.xml file in all folders

MyProject/
res/
   values/string.xml
   values-fr/string.xml
   values-ur/string.xml

suppose you have a button and you want to set text of that button according the language you choose... add the contents in all string.xml files like this

"for string.xml in values folder(default folder) this is by default for english"

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">create</string>
</resources>

"for string.xml in values-ar" that is for french

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">créer</string>
</resources>

"for string.xml in values-ur" that is for urdu

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">تخلیق</string>
</resources>

now you have created content in string.xml for all three languages. The point to note is that in all string.xml files keep the value for name attribute same

<string name="my_button">Create</string> 

here the value for name attribute is "my_button" and its same in all three string.xml. Only you have to change the text between the tags that is create for english créer for french and تخلیق for urdu... now set the text of the button like this

android:text="@string/my_button"

now the question is there are three string.xml files here in your project and from which string.xml the app will set the text of button???? this depends upon the locale of your phone. application will automatically pick text from string.xml according to locale of your phone. suppose the locale of your phone is set to french then app will pick the text from string.xml which is in values-ar folder and text on button will be créer.. if locale is set to urdu app will pick text from string.xml that is for urdu in values-ur folder and text on button will be تخلیق.. you can change the locale of app programatically.. what you have to do with radio buttons ? just change the locale according to the radio button selected..... Hopefully it will help you.

for this you have to use localization concept.Do Google the Localization in android..... Create a new folder in res folder of your project for each language you want to implement in project. in that folder create a string.xml file

MyProject/
res/
   values/<-----------this is default folder

   values-fr/ <-----------this folder is for French language(fr is iso code for french language you can check the iso codes for all languages on this link http://www.w3schools.com/tags/ref_language_codes.asp)

similarly create values folder for each language suppose you also have to implement urdu in your project then you will have to create another values folder for urdu likevalues-ur/ now you have three values folders

MyProject/
res/
   values  <------ default
   values-fr <----for french
   values-ur <----for urdu

现在创建一string.xml文件夹中的所有文件

MyProject/
res/
   values/string.xml
   values-fr/string.xml
   values-ur/string.xml

suppose you have a button and you want to set text of that button according the language you choose... add the contents in all string.xml files like this

“string.xml值文件夹(默认文件夹)是由英文“默认

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">create</string>
</resources>

“string.xml值AR”是法国

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">créer</string>
</resources>

“你在值”是乌尔都语string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="my_button">تخلیق</string>
</resources>

现在你已经创建的所有三种语言string.xml内容。这一点要注意的是,在所有的string.xml文件保持相同的名称属性值

<string name="my_button">Create</string> 

here the value for name attribute is "my_button" and its same in all three string.xml. Only you have to change the text between the tags that is create for english créer for french and تخلیق for urdu... now set the text of the button like this

android:text="@string/my_button"

now the question is there are three string.xml files here in your project and from which string.xml the app will set the text of button???? this depends upon the locale of your phone. application will automatically pick text from string.xml according to locale of your phone. suppose the locale of your phone is set to french then app will pick the text from string.xml which is in values-ar folder and text on button will be créer.. if locale is set to urdu app will pick text from string.xml that is for urdu in values-ur folder and text on button will be تخلیق.. you can change the locale of app programatically.. what you have to do with radio buttons ? just change the locale according to the radio button selected..... Hopefully it will help you.

java  android  xml