几个比较重要的xml绘制按钮selector

前端之家收集整理的这篇文章主要介绍了几个比较重要的xml绘制按钮selector前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.圆角按钮

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


    <item android:state_pressed="true"><shape>
            <solid android:color="#8CD6F5" />


            <corners android:radius="4dp" />


            <stroke android:width="1dp" android:color="#8CD6F5" />
        </shape></item>
    <item><shape>
            <solid android:color="#0BADEC" />


            <corners android:radius="4dp" />


            <stroke android:width="1dp" android:color="#0BADEC" />
        </shape></item>


</selector>




2.灰色方框

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


    <stroke
        android:width="1dip"
        android:color="#88000000" />


    <corners android:radius="1dip" >
    </corners>


    <gradient
        android:centerColor="#00FFFFFF"
        android:endColor="#00FFFFFF"
        android:startColor="#00FFFFFF" />


</shape>






3.半圆按钮 比较全面
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:state_enabled="true" android:state_window_focused="false"><shape android:shape="rectangle">
            <stroke android:width="1px" android:color="#00000000" />


            <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />


            <gradient android:centerColor="#00A490" android:endColor="#00A490" android:startColor="#00A490" />


            <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
        </shape></item>
    <item android:state_pressed="true"><shape android:shape="rectangle">
            <stroke android:width="1px" android:color="#00000000" />


            <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />


            <gradient android:centerColor="#00A490" android:endColor="#00A490" android:startColor="#00A490" />


            <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
        </shape></item>
    <item android:state_checked="true"><shape android:shape="rectangle">
            <stroke android:width="1px" android:color="#00000000" />


            <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />


            <gradient android:centerColor="#00A490" android:endColor="#00A490" android:startColor="#00A490" />


            <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
        </shape></item>
    <item android:state_focused="true"><shape android:shape="rectangle">
            <stroke android:width="1px" android:color="#00000000" />


            <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />


            <gradient android:centerColor="#00A490" android:endColor="#00A490" android:startColor="#00A490" />


            <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
        </shape></item>
    <item><shape android:shape="rectangle">
            <stroke android:width="1px" android:color="#55000000" />


            <corners android:topLeftRadius="5dp" android:topRightRadius="5dp" />


            <gradient android:centerColor="#FFFFFF" android:endColor="#FFFFFF" android:startColor="#FFFFFF" />


            <padding android:bottom="4dp" android:left="4dp" android:right="4dp" android:top="4dp" />
        </shape></item>


</selector>



 <RadioButton
            android:id="@+id/headview_user_program_rb"
            style="@style/common_rb"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:background="@drawable/center_rb_selector"
            android:checked="true"
            android:padding="3dp"
            android:text="节目收藏"
            android:textColor="@color/center_rb_textcolor_selector" />
注意一定是state_checked 而不能是selected 1!
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#fff"/>
    <item android:state_checked="true" android:color="#fff"/>
    <item android:color="#666"/>
</selector>

原文链接:https://www.f2er.com/xml/298882.html

猜你在找的XML相关文章