I\'m a beginner android developer , I was trying to run this Linear Layout in eclipse :
You can go to Design mode and select "Fix" at the bottom of the warning. Then a pop up will appear (seems like it's going to register the new string) and voila, the error is fixed.
It is not good practice to hard code strings into your layout files/ code. You should add them to a string resource file and then reference them from your layout.
strings.xml
file.supporting multiple languages
as a
separate strings.xml file
can be used for each supported language@string
system please read over the
localization documentation. It allows you to easily locate text in
your app and later have it translated.support multiple languages with a single application package file
(APK).Benefits
A good practice is write text inside String.xml
example:
String.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="yellow">Yellow</string>
</resources>
and inside layout:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/yellow" />
It is not good practice to hard code strings into your layout files. You should add them to a string resource file and then reference them from your layout.
This allows you to update every occurrence of the word "Yellow" in all layouts at the same time by just editing your strings.xml file.
It is also extremely useful for supporting multiple languages as a separate strings.xml file can be used for each supported language.
example: XML file saved at res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="yellow">Yellow</string>
</resources>
This layout XML applies a string to a View:
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/yellow" />
Similarly colors should be stored in colors.xml and then referenced by using @color/color_name
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="Black">#000000</color>
</resources>
You must create them under strings.xml
<string name="close">Close</string>
You must replace and reference like this
android:text="@string/close"/>
Do not use @strings even though the XML file says strings.xml or else it will not work.