Android tips: How to use String.xml in Android

Source: Internet
Author: User

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" &GT;38PX&LT;/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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.