In android app, within that app has settings option such as English and Tamil
If user select Tamil, with in the app only display in Tamil, in all activities all labels should in Tamil. if the user select English all labels are changed to English. How to make that?
Please give any idea....
Follow this Link: Android : translate the language of whole app on click
Then Do like this, Add the string values for each locale into the appropriate file.
English (default locale), /values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">GoodMorning</string>
</resources>
Tamil, /values-tl/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">My Application</string>
<string name="hello_world">Kaalai vanakkam</string>
</resources>
Link: http://developer.android.com/training/basics/supporting-devices/languages.html
Have a look at this question.
Basically you have to put the translated Strings in a folder in the res folder.
Related
I recently started an Android project as some sort of tutorial, but rather than the same boring List/Web View most android offline tutorial app make use of, I decided to make a it a bit better using Recycler View and card View.
The main problem so far(even it may not be to the end user as long as the app works anyway) is putting the text in cardview(had no problem with images and other res) as my strings.xml is filled up and everything looks rough.
<resources>
<string name="lesson_galaxy_one_intro"> <h1><span style="color:red">Welcome to My ..... Course</span></h1>]]> </string>
<string name="lesson_galaxy_two_intro"> <![CDATA[
<h1><span style="color:red">Getting to know .....</span></h1> ]]> </string>
<string name="galaxy_one_main_neration"> <![CDATA[<h1> <span style="color:red"> ]]> </string>
<string name="galaxy_one_main_Overview"> </string>
<string name="b"> <![CDATA[ ]]></string>
<string name="c"> <![CDATA[ ]]></string></resources>
This is more of my first real project, I just want to ask how do developers package their Text. Is strings.xml the right option for apps that require many texts? Please any tip could be helpful.
I want to allow the users to enter in text using the settings template in android studio.
And display this in a textview.(which is already set)
settings_activity_settings.xml
is
<resources>
<string name="title_activity_settings">Settings</string>
<!-- General settings -->
<string name="pref_header_general">General</string>
<string name="pref_title_display_name">Enter Team 1</string>
<string name="pref_title_display_name_2">Enter Team 2</string>
</resources>
how to i retrieve this data
First of all your approach is not correct.
Because, you can't change resource files during runtime. Strings are hard-coded in the string.xml file and hence can't be changed during runtime.
I suggest you read this, it will help you understand why android framework don't want you to edit the file in runtime.
Now, the solution to your problem? Simple, save the string you get from user in to Shared Preference and load it int text views from there.
I'm trying to populate a spinner with a dropdown of real numbers. The contents are defined in Java, but in my spinners.xml, the "double-array" is being rejected. Do I have to convert to String to use spinners?
<string-array name="semester_spinner">
<item>Spring</item>
<item>Summer</item>
<item>Fall</item>
<item>Winter</item>
</string-array>
<double-array name="cred_spinner" />
No, Android has no support for a "double-array." It would be nice, considering they already have a string-array and an integer-array.
Are you sure that they need to be double, or could you use Android's built-in Integer-Array? If that is not possible, perhaps you could consider using a Typed-Array.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="cred_spinner">
<item>2.0</item>
<item>3.0</item>
<item>4.0</item>
...
</array>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DataGush Alpha</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string-array name="menu_items">
<item >Top Lists</item>
<item >Map</item>
<item >Search</item>
</string-array>
</resources>
I am getting these errors:
[2014-03-02 15:31:32 - DataGushAlpha] W/ResourceType(64288): ResXMLTree_node header size 0 is too small.
[2014-03-02 15:31:32 - DataGushAlpha] C:\Users\anshv_000\workspace\DataGushAlpha\res\values\strings.xml:12: error: Error parsing XML: mismatched tag
[2014-03-02 15:31:32 - DataGushAlpha] C:\Users\anshv_000\workspace\DataGushAlpha\res\menu\main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '#string/action_settings').
Try to check the XML file in a simple text editor for errors.
Sometimes when you let Eclipse/ADT autocomplete inline it just leaves some garbage there that is not visible in the editor somehow. It happens frequently to me.
I have had some problems with incorrect new line characters sometimes, please check the file and ensure that the xml is correct.
You should see whats wrong in the string.xml file in eclipse, shows up as a error in the editor or you could look in the problems view. If the error is not shown in the string.xml file then it's not a problem with the file, in this case the R file hasn't been updated correctly and therefore the string resource cannot be found, this happens for me from time to time. The solution to this is usually to clean and build the project, alternatively close and open the project.
Try to delete the space between item and >
<item>Top Lists</item>
<item>Map</item>
<item>Search</item>
and check this tag 'action_settings': there is no String with this tag
While I am working with help of tutorial I found this in textview android:text-"#string/hello" it shows some error.
Then I went through graphical view and right click the component and enter the text. Then that error removes and notifies me that
**Hardcoded string hello should use String resources**
In android, "#string/" refer to the string.xml in Project>res>values> location in your package explorer.
String.xml contains a xml file which refer to a string with an id.
Eg:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World</string>
<string name="app_name">My app</string>
</resources>
Here name="hello" is the id & "Hello World" is its value. When #string/hello is used, the value will be shown.
Similar is the case with "#drawable/". It will refer to the images used. and many more.
You can set text in text view programmatically. Eg:
TextView tv = (TextView)findViewById(R.id.text1); //text1 is the id u provide in xml file
tv.setText("Hello World");
I hope it helped you.
#string/hello simply notice Android to load the String in a XML file located into the /values directory (strings.xml).
hello is the ID of the String specified by name="hello" into that XML.
Android Studio is very unstable. Previously, it auto generated the corresponding statement in the string.xml . Tutorials using previous versions get beginners stuck because of that.
How string.xml works
Android Studio expects you to write all texts in one place, in the string.xml file. In all other files, you just put abbreviations. e.g.
android:text="#string/Hello_world"
means that find the abbreviation Hello_world in the string.xml file and replace it by the intended text.
In string.xml, the corresponding statement which should be written is:
<string name="Hello_world">Hello world!</string>
and that should do the job!
It is possible to just write android:text="Hello world!" (This is what hardcoding is). If you intend to be an android dev, then you would not maximize efficiency.
Why? string.xml
Having all texts in one file eases many things. Like translation if needed and easy change. However, you should choose meaningful abbreviations!