Style personal understanding is a collection of properties of the view, then a series of view (for example, TextView), as long as the style is to have the same content, such as the text of the small, color, etc., easy to modify
First of all, the most basic use, multiple TextView are displayed the same color and text, such as a small number of properties
Definition of Sytle:
[Java]View Plaincopy
- <style name="TextViewStyle1" >
- <item name="Android:textcolor" >@android:color/holo_red_light</item>
- <item name="android:textsize" >40sp</item>
- <item name="Android:layout_height" >wrap_content</item>
- <item name="Android:layout_width" >200dp</item>
- <item name="Android:background" > #ffff00ff </item>
- <item name="android:gravity" >center_horizontal</item>
- </style>
These properties are familiar and use
[HTML]View Plaincopy
- <TextView
- style="@style/textviewstyle1"
- android:layout_margintop="100DP"
- android:text="test1"/>
- <TextView
- style="@style/textviewstyle1"
- android:layout_margintop="200DP"
- android:text="test2"/>
- <TextView
- style="@style/textviewstyle1"
- android:layout_margintop="300DP"
- android:text="test3"/>
- <TextView
- style="@style/textviewstyle1"
- android:layout_margintop="400DP"
- android:text="test4"/>
[HTML]View Plaincopy
- So the result is <img src="http://img.blog.csdn.net/20140913101147703?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvagv3zw5jzte=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Center " alt="" />
[HTML]View Plaincopy
[HTML]View Plaincopy
- So we used style in < TextView and used a conflict with style to be early?
[HTML]View Plaincopy
- Modify the background and color of the first TextView:
[HTML]View Plaincopy
- <pre name="code" class="html"><TextView
- style="@style/textviewstyle1"
- android:layout_margintop="100DP"
- android:gravity="Center_horizontal"
- android:background="#ff00ff00"
- android:textcolor="#ffffffff"
- android:text="test1"/>
So the result is
[HTML]View Plaincopy
- As you can see, the properties of the associated view include all the attributes in the style, and the view defines the
[HTML]View Plaincopy
- Properties in style that are not useful in view are automatically ignored
[HTML]View Plaincopy
Inheritance of 2.style
1. Add the Parent
<style name= "TextViewStyle2" parent= "@style/textviewstyle1" >
<item name= "Android:layout_width" >400dp</item>
</style>
2. Add
<style name="Textviewstyle1.test">
<item name= "Android:layout_width" >800dp</item>
</style>
You can also inherit multiple:
<style name= "TextViewStyle1.test.test" >
<item name= "Android:layout_width" >1200dp</item>
</style>
Then the layout file is changed to:
[HTML]View Plaincopy
- <TextView
- style="@style/textviewstyle1"
- android:layout_margintop="100DP"
- android:gravity="Center_horizontal"
- android:background="#ff00ff00"
- android:textcolor="#ffffffff"
- android:text="test1"/>
- <TextView
- style="@style/textviewstyle1.test.test"
- android:layout_margintop="200DP"
- android:text="test2"/>
- <TextView
- style="@style/textviewstyle2"
- android:layout_margintop="300DP"
- android:text="test3"/>
- <TextView
- style="@style/textviewstyle1.test"
- android:layout_margintop="400DP"
- android:text="test4"/>
The output results are as follows:
Sytle more properties See the Android package under the R.attr, these are the system Oh!
Use theme, this is fierce, changed later will affect the display of the program:
The system default is:
[HTML]View Plaincopy
- <application
- android:allowbackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/apptheme" >
I'm going to
[HTML]View Plaincopy
- Apptheme Modify it:
[HTML]View Plaincopy
- Added two elements:<pre name="code" class="html"> <style name=" Appbasetheme " parent="android:Theme.Holo.Light.DarkActionBar ">
- <!--API Theme customizations can go.
- <strong><item name="android:textsize">60sp</Item >
- <item name="Android:typeface">monospace</Item></ strong>
- </style>
Then the system all the text of the large and small is 60sp, font use monospace (unless your view is redefined)
More system style can be found in:
sdk\platforms\andrid-$API \DATA\RES\THEMES.XM Styles.xml
The use of the Android style