1

it gives me error on state_pressed , android:color, android:width is not declared.

 <selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:state_pressed="true" >
        <shape>
          <solid
              android:color="#ef4444" />
          <stroke
              android:width="1dp"
              android:color="#992f2f" />
          <corners
              android:radius="6dp" />
          <padding
              android:left="10dp"
              android:top="10dp"
              android:right="10dp"
              android:bottom="10dp" />
        </shape>
      </item>

    </selector>
Mohamed Yehia
  • 39
  • 2
  • 5

2 Answers2

0

I'm not sure in which context that you are using this selector, but apply to a button it works fine:

enter image description here

layout/Main.axml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/myButton"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_selector"
        android:text="StackoverFlow" />
</LinearLayout>

drawable/bg_selector (your axml):

<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape>
      <solid
          android:color="#ef4444" />
      <stroke
          android:width="1dp"
          android:color="#992f2f" />
      <corners
          android:radius="6dp" />
      <padding
          android:left="10dp"
          android:top="10dp"
          android:right="10dp"
          android:bottom="10dp" />
    </shape>
</item>

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
0

Nothing worked for me. But I started a new project and started to copy and paste the same code from the old project and it worked. Try it may be this is the only possible solution.

ali haider
  • 333
  • 3
  • 13