1. Introduce
When making Android apps, there are a lot of strings, some text, and here's a way to encapsulate all the strings in a String.xml file and control the size of the string by Styles.xml. In code, just call the ID of a string. This is in line with object-oriented programming ideas, but it also makes Android more adaptable to a variety of resolution phones!
2. Concrete implementation
First, we set up String.xml under the Value folder to hold string and establish styles.xml to control the properties of string. (Ignoring other XML)
In String.xml, we declare some string, and note that the name
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
<string name= "Hello" >hello world, gameactivity!</string>
<string name= "app_name" > Dart dart </string>
<string name= "Help" > Help information \ n This game is a single point darts game \ n Click on the screen launch darts \ n Combo can get higher scores </string>
<string name= "about" > About game \ n Thistle door it creative studio produced \nrhythmmaker original class to build \ n Single point RPG hand Tour peak of technology: zixiyaoren@gmail.com
\ Art:rou7in@gmail.com</string>
< String Name= "Title_activity_other" >OtherActivity</string>
<string name= "Action_settings" > settings</string>
<string name= "Hello_world" >hello world!</string>
</resources>
In the Styles.xml
<resources> <!--Base application theme, dependent on API level.
This theme was replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices. --> <style name= "Appbasetheme" parent= "Android:Theme.Light" > <!--Theme customizat
Ions available in newer API levels can go on res/values-vxx/styles.xml while customizations related to
Backward-compatibility can go. --> </style> <!--application theme. --> <style name= "Apptheme" parent= "Appbasetheme" > <!--all customizations this are not specific To a particular api-level can go. --> </style> <style name= "Label_white" > <item name= "android:textsize" >38PX</ITEM&G t;//Font size <item name= "Android:textcolor" > #0000FF </item>//color is blue <item name= "Android:gravi Ty ">center</item>//center <item name= "Android:textstyle" >bold</item>//bold </style> </resources& Gt
After configuring the XML file, let's look at how to call it in code!
For example, we want to invoke a string named Help in String.xml. As long as the object is similar to this settext (R.STRING.HELP), the method can be called, and the use of the picture is the same!
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/