Android自定义shape的使用
2013-06-21 18:52
281 查看
MainActivity如下:
main.xml如下:
background_selector.xml如下:
default_shape.xml如下:
pressed_shape.xml如下:
textcolor_selector.xml如下:
package cn.testshape; import android.os.Bundle; import android.app.Activity; /** * Demo描述: * 自定义shape的使用 */ public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
main.xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:layout_width="250dip" android:layout_height="50dip" android:text="测试自定义shape的使用" android:background="@drawable/background_selector" android:textColor="@drawable/textcolor_selector" android:layout_centerInParent="true" android:gravity="center" /> </RelativeLayout>
background_selector.xml如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:drawable="@drawable/pressed_shape" android:state_pressed="true"/> <item android:drawable="@drawable/default_shape"/> </selector>
default_shape.xml如下:
<?xml version="1.0" encoding="utf-8"?> <!-- 定义矩形rectangle --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 定义边框颜色 --> <solid android:color="#d1d1d1" /> <!-- 定义圆角弧度 --> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" android:topLeftRadius="4dp" android:topRightRadius="4dp" /> </shape>
pressed_shape.xml如下:
<?xml version="1.0" encoding="utf-8"?> <!-- 定义矩形rectangle --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <!-- 定义边框颜色 --> <solid android:color="#7bb3f8" /> <!-- 定义圆角弧度 --> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" android:topLeftRadius="4dp" android:topRightRadius="4dp" /> </shape>
textcolor_selector.xml如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:color="#ffffff" android:state_pressed="true"/> <item android:color="#000000"/> </selector>
相关文章推荐
- android自定义背景shape使用
- 自定义背景文件,android:shape的使用!
- 自定义背景文件,android:shape的使用!
- android中使用shape自定义图形
- android 使用shape自定义圆角矩形
- Android自定义图形-Shape的使用
- Android自定义shape的使用
- Android中使用shape自定义纯色图片总结
- Android自定义矩形及selector、shape的使用
- Android自定义shape的使用
- Android中使用自定义View实现shape图形绘制
- Android编程使用自定义shape实现shadow阴影效果的方法
- Android 使用Shape自定义背景
- 自定义背景文件,android:shape的使用!
- android自定义dialog,添加了selector和shape混合使用
- android Shape使用
- android 自定义Drawable Shape 的应用
- Android中shape的使用 (转载)
- Android自定义属性的使用步骤