先定一个学习计划吧,准备把Android的开发指南重新看一遍,借博客做个记录吧。
User Interface -Styles and Themes
用户接口-样式和主题
定义:
style:A style is a collection of properties that specify the look and format for a View
or window. A style can specify properties such as height, padding, font color, font size, background color, and much more. A style is defined in an XML resource that is separate from the XML that specifies the layout.
style:是View或window的关于外观和格式的属性集合。样式的定义在xml中,在layout中指定样式,二者隔离。
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#00FF00" android:typeface="monospace" android:text="@string/hello" />可转化为:
<TextView style="@style/CodeFont" android:text="@string/hello" />
Theme:A theme is a style applied to an entire Activity
or application, rather than an individual View
(as in the example above).
Theme:是一种应用到整个Activity或Application中的style.
Defining Styles
1、文件存储:在res\values下,以xml存储。
<?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>style name--指定sytle名字,parent--继承style名
2、样式的继承
2.1 使用parent方法
2.2 使用分隔符方法,只能继承自己定义的样式。
<style name="CodeFont.Red"> <item name="android:textColor">#FF0000</item> </style>3、属性值定义item
3.1有哪些属性值,2种方法:
>可以去查看相关视图类的说明,其中有一节:xml Atributes 这些属性都可以定义。
>see the R.attr
reference
3.2有些属性只能给作为theme的style使用
>参看R.attr中window开头的属性
>A list of the standard attributes that you can use in themes can be found at R.styleable.Theme
.
注意属性前加上:"android:"
Applying Styles and Themes to the UI
应用样式和主题
1、style 在layout的xml中,指定view的style
<TextView style="@style/CodeFont" android:text="@string/hello" />
2、theme 在manifiest中为<activity><application>指定android:theme属性
<application android:theme="@style/CustomTheme">
<activity android:theme="@android:style/Theme.Dialog">
<activity android:theme="@android:style/Theme.Translucent">
Using Platform Styles and Themes
R.style
class.To use the styles listed here, replace all underscores in the style name with a period. For example, you can apply the Theme_NoTitleBar
theme with "@android:style/Theme.NoTitleBar"
.