每日日报

样式和主题

样式 把控件中用到的相同属性 抽取成主题  res->values->style.xml 声明style节点 在style节点下可以声明 item 每个item对应一个具体的控件使用的属性
1.<style name="MyTextViewStyle" >
2.         <item name="android:layout_width">wrap_content</item>
3.         <item name="android:layout_height">wrap_content</item>
4.         <item name="android:textColor">#ff0000</item>
5.         <item name="android:textSize">26sp</item>
6.         <item name="android:background">#22000000</item>
7.    </style>

样式声明之后 可以在xml布局文件中直接使用

  1. <TextView
  2. style="@style/MyTextViewStyle"
  3. android:text="@string/hello_world" />

作用 多处控件使用相同的样式 如果需要修改 只需在style.xml中修改

主题 作用跟样式类似 只不过作用 的范围不同 主题是作用在整个应用的需要在androidManifest.xml中Application节点下声明对应的
android:theme 这里声明的就是当前应用使用的主题
1.<application
2.        android:allowBackup="true"
3.        android:icon="@drawable/ic_launcher"
4.        android:label="@string/app_name"
5.        android:theme="@style/MyAppTheme" >
1.<style name="MyAppTheme" >
2.         <item name="android:background">#66ff0000</item>
3.    </style>

主题的在styles.xml中声明的方式跟样式一样 只不过作用的范围更大
原文地址:https://www.cnblogs.com/zhukaile/p/14837225.html