shape绘制圆角可变背景

shape绘制圆角带边框可变背景

button_pattern.xml文件

<?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="#0000FF"  
                android:endColor="#D1EEEE"  
                android:angle="270" />  
            <stroke  
                android:width="2dp"  
                android:color="#dcdcdc" />  
            <corners  
                android:radius="20dp" />  
            <padding  
                android:left="10dp"  
                android:top="10dp"  
                android:right="10dp"  
                android:bottom="10dp"/>
        </shape> 
    </item>

        <!-- pressed -->
    
        
    <item android:state_focused="true">
        <shape>  
            <gradient  
                android:startColor="#0000FF"  
                android:endColor="#B0E2FF"  
                android:angle="270" />  
            <stroke  
                android:width="2dp"  
                android:color="#dcdcdc" />  
            <corners  
                android:radius="2dp" />  
            <padding  
                android:left="10dp"  
                android:top="10dp"  
                android:right="10dp"  
                android:bottom="10dp"/>
        </shape>  
    </item>
       <!-- focused -->
    
       
    <item>
        <shape>  
            <gradient  
                android:startColor="#0000CD"  
                android:endColor="#B0E2FF"  
                android:angle="90" />  
            <stroke  
                android:width="2dp"  
                android:color="#dcdcdc" />  
            <corners  
                android:radius="20dp" />  
            <padding  
                android:left="10dp"  
                android:top="10dp"  
                android:right="10dp"  
                android:bottom="10dp"/>
        </shape>  
    </item> 
    <!-- default -->
</selector>

为button设置背景:

            <Button
                android:id="@+id/configButton"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_margin="3dp"
                android:layout_weight="1"
                android:background="@drawable/button_pattern"
                android:gravity="center"
                android:scaleType="centerInside"
                android:text="Config" />

 效果图:

正常:                                                          按压:

 

                                                        

posted on 2016-04-11 10:32  皮皮鲁西西  阅读(493)  评论(0编辑  收藏  举报

导航