0

I have designed my own graphics composed of two images for an Image Button - one focused and one unfocused. I have the following button in the layout and XML file for it in drawable folder:

    <ImageButton
        android:id="@+id/btnPlay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        style="?android:attr/borderlessButtonStyle"
        android:src="@drawable/btn_play" />

.

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/ic_playfocused" />
    <item android:state_focused="true" android:drawable="@drawable/ic_playfocused" />
    <item android:state_selected = "true" android:drawable = "@drawable/ic_playfocused" />
    <item android:drawable = "@drawable/ic_playdefault" />
</selector>

When I click the button, it switches the two images properly, but the problem is that I also see a partially transparent blue rectangle that normally highlights button clicks. How can I get rid of this blue highlight so that when my button is clicked, the only thing that happens is the switch between the two images?

Thank you in advance :)

Wolf
  • 135
  • 2
  • 10

1 Answers1

0

Ok so just set the button background to transparent, worked for me just now.

<ImageButton
    android:id="@+id/btnPlay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="@android:color/transparent"
    style="?android:attr/borderlessButtonStyle"
    android:src="@drawable/btn_play" />
Woodstown
  • 26
  • 5
  • see [here](http://stackoverflow.com/questions/12825613/imagebutton-doesnt-highlight-on-click-with-transparent-background) – Woodstown May 27 '14 at 13:58
  • I tried, but where? Your line has an issue with my #1 line in the selector, according to Android if I place your line after my first line, it says: "This item is unreachable because a previous item (item #1) is a more general match than this one" Respectively, if I place your line first, then my image doesn't rollover. – Wolf May 27 '14 at 13:59
  • I added **android:background="?android:selectableItemBackground"** as the last (third) attribute of my first selector item, but there was no difference. I also tried adding it to all three of my focused states, but when I press the button it doesn't many any difference again :s – Wolf May 27 '14 at 14:12
  • what about using android:background="@android:color/transparent" – Woodstown May 27 '14 at 14:29
  • I have added the attribute first to the state_pressed and then to all three states, but nothing. I think that what you are suggesting is just making the background transparent perhaps, but it doesn't remove the blue highlight on button click. Do you know another possible solution? :P – Wolf May 27 '14 at 14:38
  • Ok I made a test app with your code and I got it to work, not sure why the other way doesn't work but see my new answer :P – Woodstown May 27 '14 at 15:09
  • It works! :D Thanks a bunch for the help, mate :) Now I can finally continue on my way to the next problem XD <3 – Wolf May 27 '14 at 15:14
  • No problem, sorry for the initial run around haha – Woodstown May 27 '14 at 15:19