Android自定义Button背景色,弧度

Android自定义Button背景色,弧度

作为selector放在drawable中

  • android:state_pressed=”true” 点击
  • android:state_focused=”true” 聚焦

自定义的Button的xml文件(res/drawable/button_selector.xml)

<?xml version="1.0" encoding="utf-8"?>
<selector  xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- pressed -->
    <item android:state_pressed="true" >
        <shape android:shape="rectangle">
            <gradient  android:startColor="#ff8c00" android:endColor="#ff8c00" android:angle="270" />           
            <corners  android:radius="4dp" />
        </shape>
    </item>
   <!-- focus -->
   <item android:state_focused="true" >
        <shape>
            <gradient  android:startColor="#ffc2b7" android:endColor="#ffc2b7" android:angle="270" />            
            <corners  android:radius="4dp" />
        </shape>
    </item>
<!-- default -->
    <item>        
        <shape>
            <gradient  android:startColor="#d0d0d0" android:endColor="#d0d0d0" android:angle="0" />
            <corners  android:radius="4dp" />
        </shape>
    </item>
</selector>

引用

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="10dip"
    android:paddingTop="3dip">
    <TextView
        android:id="@+id/time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:textColor="@color/light_grey" />
    <Button
        android:id="@+id/agree"
        android:layout_width="wrap_content"
        android:layout_height="23dip"
        android:layout_toLeftOf="@+id/publish"
        android:drawableLeft="@drawable/agree_view"
        android:layout_marginRight="10dip"
        android:gravity="center"
        android:textSize="@dimen/text_size_common"
        android:textColor="@color/light_grey"
        android:background="@drawable/button_selectort" />
    <Button
        android:id="@+id/publish"
        android:layout_width="wrap_content"
        android:layout_height="23dip"
        android:layout_alignParentRight="true"
        android:drawableLeft="@drawable/reply_view"
        android:gravity="center"
        android:textSize="@dimen/text_size_common"
        android:textColor="@color/light_grey"
        android:background="@drawable/button_selector" />
</RelativeLayout> 

Android自定义Button背景色,弧度_第1张图片

你可能感兴趣的:(android,Button特效)