Android中的style,attr,theme
2013-05-27 14:12
375 查看
android 2012-03-31 10:15
738人阅读 评论(1)
收藏
举报
androidlayoutxmlcssui
总结下,免得每次忘
1)style类似于css,用来定义View等UI元素的属性,比如layout_width等,可以在layout的xml中用@style/name来引用
2)style中如果要加入自定义属性,可以在attr中定义,一个attr包括name和format属性,可以在style中用@attr/name来引用
也可以在attr中定义属性集合,用declare-styleable标签定义,这个属性集合在view的构造函数中用到
public View(Context context, AttributeSet attrs, int defStyle);
View就可以在构造函数中知道要去defStyle中的哪些属性出来
属性集的引用不同于单个属性,使用R.styleable.name来引用
3)theme一般是针对activity的,全局生效,一般在theme中指定style,而这个指定,一般由一个属性来完成,属性在attr中定义
比如attr中定义autoCompletTextViewStyle属性,然后在theme中指定
<item name="autoCompleteTextViewStyle">@android:style/Widget.AutoCompleteTextView</item>
这样就可以在View的构造函数中,利用R.attr.autoCompleteTextViewStyle取得Theme中指定的style
在 public View(Context context, AttributeSet attrs, int defStyle);
中,defStyle既可以是某一个style:R.style.name,也可以是R.attr.name,对于后者,需要在theme中指定属性值。
相关文章推荐
- Android中的style,attr,theme
- Android - Attr、Style、Theme浅析
- Android中的style,attr,theme
- Android中的style,attr,theme
- 【Android】attr、style和theme
- [Android基础]theme、style、attr之间联系与区别
- Android样式(style)和主题(theme)
- android的Style(样式)与Theme(主题)的使用
- android的样式(style)与主题(theme)
- Android 避免APP启动闪黑屏的解决办法(Theme和Style)
- Android中Style和Theme的使用
- (4.1.20)android的样式(style)与主题(theme)
- Android 避免APP启动闪黑屏的解决办法(Theme和Style)
- 基于android样式与主题(style&theme)的详解
- Android 编程下通过 Theme 和 Style 避免 APP 启动闪黑屏
- android杂记4:style & theme
- android style 与theme的区别
- android-样式和主题(style&theme)
- 【android】style和theme
- android UI进阶之style和theme的使用