Tutorial Index
- Android drag and drop tutorial
- Android plotting (drawables) Tutorial
- Android styles and themes tutorial
- Live wallpaper tutorial
- Homescreen widgets tutorial
- Custom views for Android (M m views) Tutorial
- Android supports support for different screen sizes (support different screensize) Tutorial
- Android animation (animations) Tutorial
- Android touch tutorial
1. Android styles and themes
1.1 styles)
Android allows you to define the look and feel of an Android Application in an external style file. You can apply the defined style to different views. You can define styles in an XML file and apply these styles to different components. To use XML to define styles, you only need to configure some common attributes. If you need to modify styles in the future, you can modify them in a centralized manner.
You can create an XML file under the/RES/values file of your android project. Note that the root directory of the file must be <resources>. The following example shows how to create a style. xml file in the/RES/XML directory.
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "text">
<Item name = "Android: padding"> 4dip </item>
<Item name = "Android: textappearance">? Android: ATTR/textappearancelarge </item>
<Item name = "Android: textcolor" >#000000 </item>
</Style>
<Style name = "layout">
<Item name = "Android: background"> # c0c0c0 </item>
</Style>
</Resources>
You can apply the defined style to the component (element). For example, you can use the style = "@ style/text" to apply the text style to the text element.
1.2 attributes (attributes)
You can also apply a single attribute to the android style. The following example defines the button style of Android 4.0.
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "vertical">
<Linearlayout
Style = "? Android: ATTR/buttonbarstyle"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal">
<Button
Android: Id = "@ + ID/button01"
Style = "? Android: ATTR/buttonbarbuttonstyle"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "show"/>
<Button
Android: Id = "@ + ID/button02"
Style = "? Android: ATTR/buttonbarbuttonstyle"
Android: layout_width = "0dp"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "change"/>
</Linearlayout>
<Edittext
Android: Id = "@ + ID/myview"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: EMS = "10">
<Requestfocus/>
</Edittext>
</Linearlayout>
As follows:
1.3 themes)
A topic is a style applied to the entire activity or application compared to a single view. The following example defines a theme that inherits the theme defined by Android.
<? XML version = "1.0" encoding = "UTF-8"?>
<Resources>
<Style name = "mytheme" parent = "Android: theme. Light">
<Item name = "Android: windownotitle"> true </item>
<Item name = "Android: windowbackground"> @ color/translucent_red </item>
<Item name = "Android: listviewstyle"> @ style/mylistview </item>
</Style>
<Style name = "mylistview" parent = "@ Android: style/widget. listview">
<Item name = "Android: listselector"> @ drawable/ic_menu_home </item>
</Style>
</Resources>