Outline
1|Style vs Theme
是一系列属性的集合,这些集合用来指定一个View视图的外表和格式
1.res/values文件夹下创建xxx.xml
2.xxx.xml文件中,申明style标签,指定name
3.覆盖UI控件的属性,比如android:layout_width
4.在布局文件中通过style=“@style/xxx”来引用自定义样式
在布局文件中如果UI控件再次使用width/height会将style中的覆盖
style的继承差距不大时,存在着重复性较高的属性,这时可以考虑继承已经存在的样式
如果当前的样式与其他的样式
1.通过ParentStyle.ChildStyle的方式
2.parent=“Parent”
3.在ChildStyle中可以加将ParetStyle中的样式覆盖
2||Theme
主题是一种应用于一个Activity或者是整个应用App的样式,而不是单纯的作用于一个UI控件上
1.在res/values文件夹中创建styles.xml
2.使用style标签,指定name
3.覆盖UI控件的属性/某些Activity和Application的属性
4.在AndroidManifest.xml文件中通过style=“自定义样式”给Application
或者Activity指定主题
主题和样式的区别
1.主题作用于AndroidManifest.xml文件中的Application和Activity标签,作用于整个应用或者整个Activity;二样式都是写在布局文件中的UI控件属性中,用于View,TextView
2.主题定义的样式应该是改变窗口外观的样式,如窗口标题
3.如果一个应用使用了主题,但是在布局文件中UI控件也指定了样式,则样式优先级别高
Selector 状态选择器
android:state_enabled UI控件是否可用,所有的UI控件
android:state_pressed UI控件是否被手指触碰的状态,Button,ImageView
android:state_focused UI控件是否获取到焦点EditText AutoCompleteTextView
android:state_checked UI控件是否被洗选中 checkBox RadioButton
Shape 形状选择器
定义一个UI控件的颜色,尺寸,描边,边角等
<solid> 形状的颜色填充
<gradient> 颜色渐变 如果和solid一起使用,solid失效
startColor 起始颜色
centerColor 中间颜色
endColor 结束颜色
angel 颜色渐变的角度,默认是0度,取值是45度的倍数,逆时针旋转
<stroke> 描边
android:width 设置描边的宽度
android:color 设置描边的颜色
android:dashGap 设置虚线的间隙
android:dashWidth 一个虚线的长度
<corners> 边角
radius 设置四个角度的角度 如果其他四个值都同时制定,radius失效
android:topLeftRadius 设置左上角的角度
android:topRightRadius 设置右上角的角度
android:bottomLeftRadius 设置左下角的角度
android:bottomRightRadius 设置右下角的角度
<padding> 内边距
<size> 宽高尺寸
layer-list 图层列表
定义一个UI控件的颜色,尺寸,描边,边角
<solid>
<gradient>
<stroke>
<>
1|Style vs Theme
是一系列属性的集合,这些集合用来指定一个View视图的外表和格式
1.res/values文件夹下创建xxx.xml
2.xxx.xml文件中,申明style标签,指定name
3.覆盖UI控件的属性,比如android:layout_width
4.在布局文件中通过style=“@style/xxx”来引用自定义样式
在布局文件中如果UI控件再次使用width/height会将style中的覆盖
style的继承差距不大时,存在着重复性较高的属性,这时可以考虑继承已经存在的样式
如果当前的样式与其他的样式
1.通过ParentStyle.ChildStyle的方式
2.parent=“Parent”
3.在ChildStyle中可以加将ParetStyle中的样式覆盖
2||Theme
主题是一种应用于一个Activity或者是整个应用App的样式,而不是单纯的作用于一个UI控件上
1.在res/values文件夹中创建styles.xml
2.使用style标签,指定name
3.覆盖UI控件的属性/某些Activity和Application的属性
4.在AndroidManifest.xml文件中通过style=“自定义样式”给Application
或者Activity指定主题
主题和样式的区别
1.主题作用于AndroidManifest.xml文件中的Application和Activity标签,作用于整个应用或者整个Activity;二样式都是写在布局文件中的UI控件属性中,用于View,TextView
2.主题定义的样式应该是改变窗口外观的样式,如窗口标题
3.如果一个应用使用了主题,但是在布局文件中UI控件也指定了样式,则样式优先级别高
Selector 状态选择器
android:state_enabled UI控件是否可用,所有的UI控件
android:state_pressed UI控件是否被手指触碰的状态,Button,ImageView
android:state_focused UI控件是否获取到焦点EditText AutoCompleteTextView
android:state_checked UI控件是否被洗选中 checkBox RadioButton
Shape 形状选择器
定义一个UI控件的颜色,尺寸,描边,边角等
<solid> 形状的颜色填充
<gradient> 颜色渐变 如果和solid一起使用,solid失效
startColor 起始颜色
centerColor 中间颜色
endColor 结束颜色
angel 颜色渐变的角度,默认是0度,取值是45度的倍数,逆时针旋转
<stroke> 描边
android:width 设置描边的宽度
android:color 设置描边的颜色
android:dashGap 设置虚线的间隙
android:dashWidth 一个虚线的长度
<corners> 边角
radius 设置四个角度的角度 如果其他四个值都同时制定,radius失效
android:topLeftRadius 设置左上角的角度
android:topRightRadius 设置右上角的角度
android:bottomLeftRadius 设置左下角的角度
android:bottomRightRadius 设置右下角的角度
<padding> 内边距
<size> 宽高尺寸
layer-list 图层列表
定义一个UI控件的颜色,尺寸,描边,边角
<solid>
<gradient>
<stroke>
<>