Android样式和主题

样式:style-->

 

主题:theme-->

 

  <style name="my_style">
        <item name="android:textSize">50sp</item>
        <item name="android:textColor">#ff0000</item>
        <item name= "android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>

    </style>

    <style name="my_theme">
        <item name="android:background">#ffff00</item>
        <item name="android:textColor">#ff0000</item>
        <item name= "android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>

    </style>
 <TextView
        android:text="aaa"
        style="@style/my_style"
     />
    <TextView
        android:text="bbb"
        style="@style/my_style"/>
    <TextView
        android:text="ccc"
        style="@style/my_style"/>
    <TextView
        android:text="ddd"
        style="@style/my_style"/>

 

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/my_theme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

 

 

共同点:定义方式相同

不同点:style作用范围小,一般作用于控件

theme作用范围大,一般用于activity或者application节点

style用的比较多

theme用的比较少

posted @ 2017-01-06 19:14  Youxian  阅读(188)  评论(0)    收藏  举报