为什么选择器不显示按下状态

时间:2016-12-13 11:13:46

标签: android xml

按钮样式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"
            >
            <corners
                android:radius="3dp"
                />
            <gradient
                android:angle="0"
                android:startColor="#FF63a34a"
                android:endColor="#FF477b36"
                android:type="linear"
                />
            <stroke android:width="3dip" android:color="#B1BCBE" />
        </shape>
    </item>
    <item
        android:top="50dp"
        >

        <shape
            android:shape="rectangle"
            >
            <solid
                android:color="#40000000"
                />
        </shape>
    </item>
</layer-list>

按下按钮样式的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"
            >
            <corners
                android:radius="3dp"
                />
            <gradient
                android:angle="0"
                android:startColor="#FF63a34a"
                android:endColor="#FF63a34a"
                android:type="linear"
                />
            <stroke android:width="3dip" android:color="#4F5B5D" />
        </shape>
    </item>
</layer-list>

按钮样式选择器XML:

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

    <item android:drawable="@drawable/button_round_style_pressed" android:state_selected="true"></item>
    <item android:drawable="@drawable/button_round_style_pressed" android:state_pressed="true"></item>
    <item android:drawable="@drawable/button_round_style"></item>

</selector>

AlertDialog自定义XML:

<LinearLayout
    android:layout_width="0dp"
    android:layout_weight="0.2"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:background="@drawable/button_round_style_selector"
    android:padding="10dp"
    android:layout_marginRight="5dp">
    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:background="@drawable/home_white"/>
</LinearLayout>

当我按下LinearLayout时,选择器工作不正常?它不会将可绘制状态更改为按下状态。

1 个答案:

答案 0 :(得分:1)

LinearLayout默认情况下无法点击,除非您为其clickable标记为真,否则其后台不会更改,或为其分配OnClickListener