I. Styles and Themes in Android
1, 1 Style
A style is an action on a control, and it is a collection that contains one or more view control properties. Android style similar to web design CSS design ideas, can make the design and content separation, easy to inherit, reuse, reuse
Here's a simple case to demonstrate the use of custom styles, in which we customize a style for rendering the button control's display
Add in the Res/values/styles.xml file
<stylename= "Bt_style_1"> <Itemname= "Android:layout_height">Wrap_content</Item> <Itemname= "Android:layout_width">Match_parent</Item> <Itemname= "Android:textsize">20sp</Item> <Itemname= "Android:textcolor">#00ff00</Item> <Itemname= "Android:text">Custom Style 1</Item> </style> <!--inherit the above style, overwriting if the property is the same - <stylename= "Bt_style_2"Parent= "Bt_style_1"> <Itemname= "Android:textsize">30sp</Item> <Itemname= "Android:text">Custom Style 2</Item> </style>
In the layout file under Res/layout, add two button
<style= "@style/bt_style_1"/><Style = "@style/bt_style_2"/>
Results show
2, 2 Themes
The definition and style of the theme are the same, under the Styles.xml file, you can inherit a parent style by setting the parent property, but the theme is always used on the activity
Topics are scoped to the entire application or to an activity by defining the "Android:theme" attribute in the Androidmanifest.xml file and under the node. If an app uses a theme, and the view under the app uses a style,
When themes and style attributes conflict, the style takes precedence over the theme.
The Android system also defines some topics that can be viewed in the reference/android/r.style of the document if needed.
Continue to use the modified Styles.xml file in the above style to add the following style
<!--The topic is also defined by defining the <style> node in the Styles.xml file. As with styles, specify a globally unique name for the theme, inheriting the parent style through the parent property. -<stylename= "Theme_notitle"><!--This property makes the interface untitled -<Itemname= "Android:windownotitle">True</Item></style><!--This property makes the interface full screen -<stylename= "Them_notitle_full"Parent= "Theme_notitle"><Itemname= "Android:windowfullscreen">True</Item></style>
Add in the Androidmanifest.xml file
<!--introduction of themes in application all activity is applicable -<ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/theme_notitle" ><!--introduction of topics in activity is currently available for activity -<ActivityAndroid:theme= "@style/them_notitle_full"Android:name= "Com.example.styleAndTheme.MainActivity"Android:label= "@string/app_name" ><Intent-filter><ActionAndroid:name= "Android.intent.action.MAIN" />
Second, Android to achieve internationalization
The internationalization of the Android program is that the program can translate the text in the interface into the language of the object according to the language used by the system. In this way, the program can be more general, Android can be easily through the resource files to achieve the internationalization of the program
When writing an Android project, it is common to place the string resources in the program to be used in the Strings.xml file in the Res/values directory, in order to internationalize these string resources, in the Res directory of the Android project, Create a resource folder for each language (for example, to make the program compatible with Simplified Chinese, Traditional Chinese, and American English, you can create folders named Values-zh-rcn, Values-zh-rtw, and Values-en-rus, respectively), Then create a corresponding Strings.xml file in each folder and define the corresponding language string in the file. When the program is running, the corresponding string information is automatically displayed according to the language used by the operating system. The image can also be internationalized, similar to the internationalization of the string, just according to the language version of the program to be compatible, create a folder with the name similar to DRAWABLE-ZH-RCN,DRAWABLE-ZH-RTW, and store the picture resources in the folder.
Style themes and internationalization in Android