您的位置:首页 > 移动开发 > Android开发

android中shape与selector的使用

2013-08-18 21:41 711 查看
最近又要做android项目,没办法,又得学学android了,多么希望这个世界只有C++.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<!-- 渐变效果 -->
<gradient android:startColor="#8600ff" android:endColor="#ffffff" android:angle="270"></gradient>
<!-- 描边、边框 -->
<stroke android:width="2dp" android:color="#000000"></stroke>
<!-- 圆角 -->
<corners android:radius="5dp"></corners>
<!-- 间隔 -->
<padding android:left="10dp" android:top="10dp" android:bottom="10dp"
android:right="10dp"></padding>
</shape>
</item>

<item android:state_pressed="false">
<shape>
<gradient android:startColor="#eac100"></gradient>
<stroke android:width="2dp" android:color="#333333"></stroke>
<corners android:radius="8dp"></corners>
<padding android:left="10dp" android:top="10dp" android:bottom="10dp"
android:right="10dp"></padding>
</shape>
</item>
</selector>

使用方法:

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:focusable="true"
android:background="@drawable/button_color" />


效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: