Android style
Styles in Android, like CSS styles, are used to define a display style for an interface element, which is a collection that contains one or more view control properties . For example, you need to define the color and size of the font.
This is defined in CSS:
<style>.wu {COLOR:#0000CC; font-size:18px;} </style>
You can use the above CSS style like this: <div class= "WU" >wuyudong ' blog</div>
In Android, you can define styles like this:
Add the following in the Res/values/styles.xml file
<?XML version= "1.0" encoding= "Utf-8"?><Resources><stylename= "WU" ><!--define a globally unique name for the style-><Itemname= "Android:textsize" >18px</item><!--The value of the Name property is the property of the view control that uses the style--><Itemname= "Android:textcolor">#0000CC</Item></style></Resources>
The above Android style can be used in the layout file as follows:
<? XML version= "1.0" encoding= "Utf-8" ?> < xmlns:android= "Http://schemas.android.com/apk/res/android" ... . > < style= "@style/wu"/></linearlayout >
Here's how to practice
Add the following code to the Style.xml:
<Resourcesxmlns:android= "Http://schemas.android.com/apk/res/android"> <!--Base application theme, dependent on API level. This theme are replaced by Appbasetheme from Res/values-vxx/styles.xml on newer devices. - <stylename= "Appbasetheme"Parent= "Android:Theme.Light"> <!--Theme customizations available in newer API levels can go in res/values-vxx/styles.xml, while C Ustomizations related to Backward-compatibility can go. - </style> <!--application theme. - <stylename= "Apptheme"Parent= "Appbasetheme"> <!--All customizations, that is, specific to a particular api-level can go. - </style> <stylename= "Text_content_style"Parent= "Appbasetheme"> <Itemname= "Android:layout_width">Wrap_content</Item> <Itemname= "Android:layout_height">Wrap_content</Item> <Itemname= "Android:textcolor">#66ff00</Item> <Itemname= "Android:textsize">20sp</Item> </style></Resources>
The layout code is as follows:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context=". Mainactivity " > <TextViewstyle= "@style/text_content_style"Android:text= "I am a text" /> <TextViewstyle= "@style/text_content_style"Android:text= "I am a text" /> <TextViewstyle= "@style/text_content_style"Android:text= "I am a text" /> <TextViewstyle= "@style/text_content_style"Android:text= "I am a text" /> <TextViewstyle= "@style/text_content_style"Android:text= "I am a text" /></LinearLayout>
After you run the project
Android Themes
The theme in Android is also used to define the display style for the app, which defines the same definition as the style, as follows:
<?XML version= "1.0" encoding= "Utf-8"?><Resources><stylename= "Wutheme" ><item name= "Android:windownotitle" >true</item><!–-No title--><item name= "Android:windowfullscreen" >?android:windowNoTitle</item><!–-Full Screen display--></style></Resources>
The question mark in "? Android:windownotitle" above is used to refer to the value of the resource defined in the current topic. The following code shows how to set the topics defined above for your app in Androidmanifest.xml:
<android:icon= "@drawable/icon" android:label= "@string/app_name" android:theme= "@style/wutheme"> ... </ Application >
In addition to setting themes in Androidmanifest.xml, you can also set themes in your code, as follows:
SetTheme (R.style.itcasttheme);
Although the styles and themes are basically the same on the definition, they are used in different places. The style is used in separate view, such as: EditText, TextView, etc., subject through the Androidmanifest.xml <application> and <activity> used in the entire application or a Activity, which has a global impact on the entire application or on an activity. If a theme is used by an app, and the view under the app also uses styles, the style takes precedence over the theme when the theme and style properties conflict.
In addition, the Android system also defines a number of topics, such as: <activity android:theme= "@android: Style/theme.dialog", which allows the activity to look like a dialog box, There are also transparent topics: @android: Style/theme.translucent. If you need to consult these topics, you can view them in the Reference?android-->r.style of your document.
Android Styles and Themes (style & theme)