0

I have two imagebuttons in a LinearLayout with the following:

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imgImport"
        android:layout_margin="6dp"
        android:clickable="true"
        android:background="@drawable/bgselector2"
        android:src="@drawable/player_import" />

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imgEdit"
        android:layout_margin="6dp"
        android:clickable="true"
        android:src="@drawable/players"
        android:background="@drawable/bgselector" />

The selector on the second imagebutton works properly but the first image button with the following simple selector does not! Why is that?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true" android:drawable="@drawable/players_import_pr" />
<item android:state_enabled="true" android:drawable="@android:color/transparent" />
</selector>
  • for default and press state one is enough? –  Jun 13 '16 at 14:06
  • do your linear layout have orientation attribute? it's possible is over the button, the other one... are you assigning the right file name to your your button? – Rene Limon Jun 13 '16 at 14:16
  • Its a Linear with horizontal orientation containing a TextView,ImageButton,ImageButton –  Jun 13 '16 at 14:18
  • is recommended to only assign background attribute when using selector, for example: http://stackoverflow.com/questions/14023886/android-button-selector – Rene Limon Jun 13 '16 at 14:24

1 Answers1

0

Try to add android:state_pressed="false" for second state:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true"  android:drawable="@drawable/players_import_pr" />
<item android:state_pressed="false" android:state_enabled="true" android:drawable="@android:color/transparent" />
</selector>

Or maybe you should have transparent as default item?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true"  android:drawable="@drawable/players_import_pr" />
<item android:drawable="@android:color/transparent" />
</selector>