样式和主题本质是外观属性的集合,
1. 共同点 定义的方式一样
2. 不同的 样式作用范围比较窄 比如textview button 主题作用范围比较广 主要作用在application 或者作用在Activity上
使用步骤:
1.在android项目的res/values/s'tyles.xml文件中添加样式或主题
<style name="my_textview">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">30sp</item>
<item name="android:textColor">#ff0000</item>
</style>
<style name="my_theme">
<item name="android:background">#ff0000</item>
</style>
2.在需要设置样式的控件中引用该样式或主题
引用样式
<TextView
style="@style/my_textview"
android:text="1111" />
<TextView
style="@style/my_textview"
android:text="2222" />
引用主题<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/my_theme" >
<activity
android:name="com.itheima.styletheme.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>
版权声明:本文为rankun1原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。