Using Selector to change ImageButton's background while keeping the content image

by Sebastian Mauer » Sun, 18 Apr 2010 23:18:36 GMT

Sponsored Links
 Hi there,

I am currently trying to customize ImageButton to show different
draweables as background of the Button while keeping
the image set via the src attribute.

That's my custom_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="" ;>
     <item android:state_pressed="true"
           android:drawable="@drawable/round_list_item" /> <!--
pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/round_list_item" /> <!--
focused -->
     <item android:drawable="@drawable/transparent" /> <!-- default --

And this is the actual definition of the ImageButton:
<ImageButton android:background="@drawable/custom_button"
android:src="@drawable/attach_icon" android:id="@+id/test_button"
android:layout_height="35dip" android:layout_width="35dip"></

Unfortunately all I get is the background from the selector xml
(whichs is btw working as expected) but not the image I have set via
the src attribute.
So basically all I want is to replace the standard state background
drawables while keeping the ability to set a foreground/content image.

Am I doing something wrong here?




Using Selector to change ImageButton's background while keeping the content image

by Sebastian Mauer » Wed, 21 Apr 2010 03:32:04 GMT

 Is this even possible?


Sponsored Links

Other Threads

1. How to add text in ImageButton

Hi all,
    I want to use an imagebutton in my application, but only a button
with image can not indicate  its function clearly. If there are some
text beside the button, I think everything will be more explicit.
   But I don't know how to add text in an imagebutton in Android.Can
anyone help me with code?If text is not supported in imagebutton, can
I define my own "imagebutton" which can show text by extending
ImageButton, and how to do this?
    Thank you in advance!


2. Uninstall / Signature problem on G1 device


I installed a development version of an app on my G1 with 1.1 firmware
build TMI-RC9 128600 running through adb. I then tried to uninstall it
with adb and install a newer version for which I used a different
signature. This has always worked but now even after uninstalling I
get a signature error when trying to install the app again
(INSTALL_FAILED_UPDATE_INCOMPATIBLE). Does the device store signatures
now somewhere even after uninstall? This would be a bit annoying for
development purposes. Any information on this and how to get rid of
the old installation?


3. Need help on BroadcastReceiver::

4. Developing browser plugin for Android web browser

5. adb is not detecting my android phone

6. OT: 100s of old group emails

7. "send" intent only when activity is on top running