Styles and Themes
来源:互联网 发布:一淘网好还是淘宝网好 编辑:程序博客网 时间:2024/05/17 03:46
1.概述
style是属性的集合,用来指定view或者window的外观和版式。style可以指定诸如高度,填充,字体颜色,字体大小,背景颜色等属性。style定义在与layout文件分开的xml资源文件中。
例如可以如下使用style:
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />
使用style之后:
<TextView style="@style/CodeFont" android:text="@string/hello" />所有的style属性都被从layout xml文件中移除,然后写到一个style xml文件中,命名为:
CodeFont
。theme是一种style,运用在所有的activity或者application。
2.创建style
在工程目录res/values/
下,创建一个文件,名字随意,保存style属性集。xml文件的根节点必须是<resources>
。
例子如下:
<?xml version="1.0" encoding="utf-8"?><resources> <style name="CodeFont" parent="@android:style/TextAppearance.Medium"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#00FF00</item> <item name="android:typeface">monospace</item> </style></resources>
在编译的时候
<resources>
的子元素都会被转换成一个application资源对象。可以通过name来引用。parent
属性可选,可以指定为另一个style文件的id。3.继承
<style>
元素中的parent
属性可以指定一个style,我们的定义的style继承于这个style。可以使用这一属性继承已有的style,而只用定义或者改变部分的属性。
<style name="GreenText" parent="@android:style/TextAppearance"> <item name="android:textColor">#00FF00</item> </style>
比如上面例子,继承了TextAppearance,修改了textColor属性。
如果是使用继承自己定义的style,就没有必要使用parent属性了。只需要在你的新style的名字前加上已定义的style的名字。例子如下:
<style name="CodeFont.Red"> <item name="android:textColor">#FF0000</item> </style>
4.style的属性值
现在已经知道如何定义一个属性文件了,下面来看看在style文件中可以定义那些属性item。查看指定view的属性的最好的方法就是查看class 参考文档。比如TextView
所有可利用的属性都在TextView XML attributes列出来了。
参考文档http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles
1 0
- Applying styles and themes
- Android Styles and Themes
- Styles and Themes
- Styles and Themes
- android--Styles and Themes
- Android - Styles and Themes
- Styles and Themes
- styles and themes
- Android-Styles and Themes
- android-Styles and Themes
- Styles and Themes
- Styles and Themes
- Applying themes and styles(3)_Applying themes and styles
- Use Platform Styles and Themes
- android Platform Styles and Themes
- 如何学习Styles and Themes
- Android中的Styles and Themes
- Android之Styles and Themes
- CCLableTTF在andorid和ios的getContentSize().height不一样
- 枚举
- Cordova v3.4.1 Android不能定位问题
- 读而生厌的“中国式管理”
- C++中数字与字符串之间的转换
- Styles and Themes
- struts2的Result组件
- typed的使用
- win8 应用体验
- Java 编程下的同步代码块(售票员)
- twitter storm源码走读之6 -- Trident Topology执行过程分析
- 赵伯平--警惕台湾的企业管理垃圾!
- Android数字签名解析(三)
- Downloadmanager