[关闭]
@act262 2017-08-09T12:39:49.000000Z 字数 1332 阅读 743

Android Theme

theme


Android 主题

attr声明可用属性

对应文件/res/values/attrs.xml

  1. <resources>
  2. <!--熟悉的主题中的属性 -->
  3. <declare-styleable name="Theme">
  4. ...
  5. <attr name="windowBackground" format="reference" />
  6. <attr name="windowNoTitle" format="boolean" />
  7. <attr name="windowFullscreen" format="boolean" />
  8. ...
  9. </declare-styleable>
  10. <!-- 熟悉的View的属性 -->
  11. <declare-styleable name="View">
  12. <attr name="id" format="reference" />
  13. <attr name="background" format="reference|color" />
  14. ...
  15. </declare-styleable>
  16. ...
  17. </resources>

在内部声明、外部声明属性
i.e. 在外部声明了orientation属性,然后在LinearLayout的内部中直接引用

  1. <attr name="orientation">
  2. <enum name="horizontal" value="0" />
  3. <enum name="vertical" value="1" />
  4. </attr>
  1. <declare-styleable name="LinearLayout">
  2. <attr name="orientation" />
  3. ...
  4. <declare-styleable>

也可以把orientation属性放到LinearLayout内部声明

  1. <declare-styleable name="LinearLayout">
  2. <attr name="orientation">
  3. <enum name="horizontal" value="0" />
  4. <enum name="vertical" value="1" />
  5. </attr>
  6. ...
  7. <declare-styleable>

外部声明的属性可以在多个地方引用,内部声明的属性只能在当前样式引用

style实现具体的样式

对应的文件/res/values/themes.xml

  1. <resources>
  2. <style name="Theme">
  3. <!-- Window attributes -->
  4. <item name="windowBackground">@drawable/screen_background_selector_dark</item>
  5. <item name="windowNoTitle">false</item>
  6. <item name="windowFullscreen">false</item>
  7. </style>
  8. <style name="Theme.Light">
  9. <item name="windowBackground">@drawable/screen_background_selector_light</item>
  10. </style>

可以给Activity指定不同主题样式

主题中的style、declare-styleable、attr的关系

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注