[android] 样式与主题1-样式style

Android 4.0

样式style

1、在
下配置:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, DemoActivity!</string>
    <string name="app_name">Style</string>
   
    <style name="test_style">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textSize">18sp</item>
        <item name="android:textColor">#00ffff</item>
    </style>
   
    <style name="test_style1" parent="@style/test_style">  //继承父类style,可以重写父类样式
          <item name="android:textSize">28px</item>
    </style> 
</resources>

2、main.xml中引用

  1) 引用
    <TextView 
       style="@style/test_style"
       android:text="hello2"/>
  2) 对于引用的style复写
    <TextView
       style="@style/test_style"
       android:text="hello5"
       android:textSize="10px"/>
  3) 继承父类的style
    <TextView
       style="@style/test_style1"
       android:text="hello5"/>

效果:
      

完整代码:   

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
       style="@style/test_style"
       android:text="@string/hello"
        />
    <TextView
       style="@style/test_style"
       android:text="hello2"/>
    <TextView
       style="@style/test_style"
       android:text="hello3"
        />
    <TextView
       style="@style/test_style"
       android:text="hello4"
        />
    <TextView
       style="@style/test_style"
       android:text="hello5"
       android:textSize="10px"
        />
    <TextView
       style="@style/test_style1"
       android:text="hello5"
        />

</LinearLayout>