介绍
小编给大家分享一下如何使用XML资源文件来定义颜色,样式等,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!
1,使用XML资源文件来定义颜色该方法扩展性好,便于修改和共享,如在价值观目录下创建一个颜色。xml
,,,& lt; color name=癿ycolor"在# ffb52121, & lt;/resources>
定义了一个名为mycolor的颜色,在别的地方就可以通过引用mycolor来获取该颜色值,如
textView定义中:
Android:输入textColor=癅drawable/mycolor"
2,使用xml资源文件来定义样式在res/可拉的中定义一个形状。xml文件
实例代码:
& lt; ? xml version=?.0“,编码=皍tf-8" ?祝辞,, & lt; shape  xmlns: android=癶ttp://schemas.android.com/apk/res/android",在,, ,, ,,,& lt; corners android:半径=? dp",/在,, ,, ,,,& lt; size , ,,,,,,,android:身高=?0 dp",, ,,,,,,,android:宽度=?0 dp",/在,, ,, ,,,& lt; gradient ,, ,,,,,,,android: startColor=? 9933 cc",, ,,,,,,,android: endColor=? aa66cc",, ,,,,,,,android:角=?0“,,, ,,,,,,,/在,, ,,,,, ,,,& lt; padding android:左=? dp",, ,,,,,,,android:右=? dp",, ,,,,,,,android:顶级=? dp",, ,,,,,,,android:底部=? dp"/祝辞,, ,, & lt;/shape>,, & lt; ? xml version=?.0“,编码=癠TF-8" ?比; & lt; shape  xmlns: android=癶ttp://schemas.android.com/apk/res/android" ,,,android:形状=皉ectangle",在 , ,,,& lt; !——,填充的颜色:这里设置背景透明,——比; ,,,& lt; solid android:颜色=癅android:颜色/transparent",/比; ,,,& lt; !——,边框的颜色,:不能和窗口背景色一样,比; ,,,& lt;中风 ,,,,,,,android:宽度=? dp" ,,,,,,,android:颜色=? ffffff",/比; ,,,& lt; !——,设置按钮的四个角为弧形,——比; ,,,& lt; !——, android: radius 弧形的半径,——比; ,,,& lt; corners android:半径=? dip",/比; , ,,,& lt; !——,填充:按钮里面的文字与按钮边界的间隔,——比; ,,& lt;填充 ,,,,,,,android:底部=?0 dp" ,,,,,,,android:左=?0 dp" ,,,,,,,android:右=?0 dp" ,,,,,,,android:顶级=?0 dp",/比; & lt;/shape>
在你的活动的xml(比如activity_main.xml)中定义按钮
& lt;按钮 ,,,android: id=癅 + id/roundButton" ,,,android: layout_width=皐rap_content" ,,,android: layout_height=皐rap_content" ,,,android:背景=癅drawable/shape" ,,,android:文本=?圆角按钮,“,/在
形状的属性:
固体
描述:内部填充
属性:android:颜色填充颜色大小
描述:大小
属性:
,,,,,android: width 宽 ,,,,,,,,,,,,,,,,android: height 高梯度
描述:渐变色
属性:
,,,,,android: startColor渐变起始颜色 ,,,,,,,,,,,,,,,,,,android: endColor渐变结束颜色 ,,,,,,,,,,,,,,,,,,android: centerColor渐变中间颜色 ,,,,,,,,,,,,,,,,,,android: angle 渐变的角度,角=0时,渐变色是从左向右,然后逆时针方向转;当角=90时,渐变色从上往下.angle必然是45的倍数 ,,,,,,,,,,,,,,,,,,android: type 渐变类型:线性(线性),径向(放射性,以开始色为中心),扫描(扫描线式渐变) null null null null null null null null null null null null null null如何使用XML资源文件来定义颜色,样式等