Android的应用层列表按钮选择按钮、应用层、列表、Android

由网友(情歌总在分手后)分享简介:我们如何使用图层列表作为绘制的按钮。我有一个按钮:How do we use a layer-list as a drawable for a button.I have a button:我们如何使用图层列表作为绘制的按钮。 我有一个按钮:     

How do we use a layer-list as a drawable for a button. I have a button:

<item android:state_pressed="true">
    <shape>
        <gradient android:endColor="@color/white"
            android:startColor="@color/grey_blue_light" android:angle="90" />
        <stroke android:width="1dp" android:color="@color/aqua_blue" />
        <corners android:radius="3dp" />
        <padding android:left="10dp" android:top="10dp"
            android:right="10dp" android:bottom="10dp" />
    </shape>
</item>


<item android:state_focused="true">

</item>
<item>

</item>

现在我需要的时候说的按钮状态为pressed用作形状图层列表:

Now I need a layer-list to be used as a shape when say button state is pressed:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="oval">
        <solid android:color="@color/aqua_blue" />
    </shape>
</item>
<item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="1dp">
    <shape android:shape="oval">
        <solid android:color="@color/aqua_blue" />
    </shape>
</item>

如何使用这些图层列表中的按钮选择?

How do we use this layer list in the button selector?

推荐答案

步骤1 下创建文件夹,绘制了三种不同layer_list XML三种不同的按钮的状态。例如那些XML名称是 layer1.xml,layer2.xml,layer3.xml

Step-1 create three different layer_list xml under drawable folder for three different state of button. example the name of those xml is layer1.xml, layer2.xml, layer3.xml

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

            <gradient
                android:angle="270"
                android:startColor="#0000ff"
                android:endColor="#0000dd"
                android:type="linear"
                />    
        </shape>
    </item>

</layer-list>

步骤2 创建命名为btn_background.xml一个选择XML,并通过layer_list XML的可绘制属性

Step-2 create a selector xml named as btn_background.xml and pass the layer_list xml in drawable attribute

<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:drawable="@drawable/layer1">

    </item>

    <item android:state_focused="true" android:drawable="@drawable/layer2">

    </item>

    <item android:drawable="@drawable/layer3">        

    </item>
</selector>

步-3 将选择SML的按钮的android背景:背景=@可绘制/ btn_background

step-3 Set the selector sml as background of the button android:background="@drawable/btn_background"

阅读全文

相关推荐

最新文章