The use of the Android style

Source: Internet
Author: User

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
  1. <style name="TextViewStyle1" >
  2. <item name="Android:textcolor" >@android:color/holo_red_light</item>
  3. <item name="android:textsize" >40sp</item>
  4. <item name="Android:layout_height" >wrap_content</item>
  5. <item name="Android:layout_width" >200dp</item>
  6. <item name="Android:background" > #ffff00ff </item>
  7. <item name="android:gravity" >center_horizontal</item>
  8. </style>

These properties are familiar and use

[HTML]View Plaincopy
  1. <TextView
  2. style="@style/textviewstyle1"
  3. android:layout_margintop="100DP"
  4. android:text="test1"/>
  5. <TextView
  6. style="@style/textviewstyle1"
  7. android:layout_margintop="200DP"
  8. android:text="test2"/>
  9. <TextView
  10. style="@style/textviewstyle1"
  11. android:layout_margintop="300DP"
  12. android:text="test3"/>
  13. <TextView
  14. style="@style/textviewstyle1"
  15. android:layout_margintop="400DP"
  16. android:text="test4"/>
[HTML]View Plaincopy
    1. 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
    1. So we used style in < TextView and used a conflict with style to be early?
[HTML]View Plaincopy
    1. Modify the background and color of the first TextView:
[HTML]View Plaincopy
  1. <pre name="code" class="html"><TextView
  2. style="@style/textviewstyle1"
  3. android:layout_margintop="100DP"
  4. android:gravity="Center_horizontal"
  5. android:background="#ff00ff00"
  6. android:textcolor="#ffffffff"
  7. android:text="test1"/>

So the result is

[HTML]View Plaincopy
    1. 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
    1. 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
  1. <TextView
  2. style="@style/textviewstyle1"
  3. android:layout_margintop="100DP"
  4. android:gravity="Center_horizontal"
  5. android:background="#ff00ff00"
  6. android:textcolor="#ffffffff"
  7. android:text="test1"/>
  8. <TextView
  9. style="@style/textviewstyle1.test.test"
  10. android:layout_margintop="200DP"
  11. android:text="test2"/>
  12. <TextView
  13. style="@style/textviewstyle2"
  14. android:layout_margintop="300DP"
  15. android:text="test3"/>
  16. <TextView
  17. style="@style/textviewstyle1.test"
  18. android:layout_margintop="400DP"
  19. 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
    1. <application
    2. android:allowbackup="true"
    3. android:icon="@drawable/ic_launcher"
    4. android:label="@string/app_name"
    5. android:theme="@style/apptheme" >

I'm going to

[HTML]View Plaincopy
    1. Apptheme Modify it:
[HTML]View Plaincopy
  1. Added two elements:<pre name="code" class="html"> <style name=" Appbasetheme " parent="android:Theme.Holo.Light.DarkActionBar ">
  2. <!--API Theme customizations can go.
  3. <strong><item name="android:textsize">60sp</Item >
  4. <item name="Android:typeface">monospace</Item></ strong>
  5. </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

Related Article

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.