<SPAN COLOR: ">一.自定义控件的选中效果

在drawable文件夹下新建selector类型的xml文件(右键drawable,选择新建android xml file),文件名任意,内容如:

<?xml version="1.0" encoding="utf-8">
xmlns:android="http://schemas.android.com/apk/res/android">





?xml>

/*state_focused表示是否是非触摸状态,true表示是非触摸状态。其中android:drawable可以引用drawable文件夹下其它资源文件,比如shape资源,用来实现控件常规、按下、选中等样式*。

使用方法:在布局文件中,控件的背景属性中引用这些资源,以下类同*/

<SPAN COLOR: ">二.自定义控件的外观

新建shape类型的xml文件,如:

<?xml version="1.0" encoding="utf-8">
?xml>

android:width="1px"
android:color="@color/color_black" />

android:bottom="3dp"
android:left="3dp"
android:right="3dp"
android:top="3dp" />
android:color="@color/color_white"
/>

android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:radius="1dp"
android:topLeftRadius="@dimen/indicator_corner_radius"
android:topRightRadius="@dimen/indicator_corner_radius" />

/*

stroke表示描边

padding内边距

solid表示实体,即控件的整体区域

corners表示圆角

*/

<SPAN COLOR: ">三.多样式叠加

新建layer-list类型的xml文件,如:

<?xml version="1.0" encoding="UTF-8">
?xml>



android:width="1dp"
android:color="@color/stroke" />



android:scaleGravity="center"
android:scaleHeight="5dp"
android:scaleWidth="5dp" />


<SPAN COLOR: ">综合示例:

<?xml version="1.0" encoding="UTF-8">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" >




<gradient android:startColor="#ff707070"
android:centerColor="#ff707070" android:endColor="#ff707070"
android:centerY="1" android:angle="270" />

?xml>





android:startColor="#ffaaa9a7"
android:centerColor="#ffaaa9a7"
android:centerY="1"
android:endColor="#ffaaa9a7"
android:angle="270"
/>









<gradient android:startColor="#ffA90101"
android:centerColor="#ffA90101" android:endColor="#ffA90101"
android:centerY="1" android:angle="270" />