EditText source background for each state

I want to customize my background. Therefore, I design the form in the selector for each state. but the first element is executed.

This is my code:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:color="@android:color/black" >
        <shape android:shape="rectangle" >
            <solid android:color="#FFFFFF" />
            <stroke
                android:width="1dp"
                android:color="#000000" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
            <corners android:radius="10dp" />
        </shape>
    </item>
    <item android:state_pressed="true" android:color="@android:color/black" >
        <shape android:shape="rectangle" >
            <solid android:color="#8faefd" />
            <stroke
                android:width="3dp"
                android:color="#000000" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
            <corners android:radius="10dp" />
        </shape>
    </item>
</selector>
+1
source share
1 answer

State list

With each state change, the state list moves from top to bottom and the first element that corresponds to the current state is used. the choice is not based on the “best match”, but simply on the first element that meets the minimum criteria for the state.

So, you need to change these two elements. Should be like that

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" android:color="@android:color/black" >
        <shape android:shape="rectangle" >
            <solid android:color="#8faefd" />
            <stroke
                android:width="3dp"
                android:color="#000000" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
            <corners android:radius="10dp" />
        </shape>
    </item>
    <item android:color="@android:color/black" >
        <shape android:shape="rectangle" >
            <solid android:color="#FFFFFF" />
            <stroke
                android:width="1dp"
                android:color="#000000" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
            <corners android:radius="10dp" />
        </shape>
    </item>
</selector>
+1
source

All Articles