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=" http://schemas.android.com/apk/res/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 --
</selector>

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"></
ImageButton>

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?

Greetings,

maui

--



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. Google Finance on Android XML Parse Exception

Hi I am trying to retrieve a user's portfolio information on to an
Android application using the Google Finance API, when I run the code
as a standalone application without using the Android platform, I am
able to retrieve all the portfolios and the corresponding positions.
But when I run the same on the Android platform, and try to retrieve
the positions of a particular portfolio, for the portfolios which have
even-numbered portfolio ids, the positions are being retrieved
correctly, but for the odd-numbered-portfolioid portfolios a XMLParser
ParseException is being thrown. Does any body have an idea as to why
this could be happening?

Thanks
Sid

--~--~---------~--~----~------------~-------~--~----~

2. Share GPS data to an external interface

I've never developed apps before, but I've found myself with "all the
time in the world" to do it, and hopefully make a potential job out of
it, and build a portfolio for future "real" job opportunities. So, the
first project I want to make seems like a mix of easy and hard. Easy
to program the interface, hard to figure out the API's I need.

Indeed, I'm a beginner. My question for anyone who could help, is
where would I find more "tutorial-based" documentation to get pointed
in the right direction? And even more specifically, what API's would I
need to focus on?

The project I'm intending to work on is, as the subject says, a means
to share GPS data to another device, in my case I want to use either
my T-Mobile Wing with TomTom mobile, or my netbook with some other
turn-by-turn GPS system installed, in conjuction with the GPS built
into the G1. Since it's taking a while (as all development does) for
the big Navigation providers to come out with a proper turn-by-turn
solution that DOES NOT require network coverage to come out, I figured
I'd find a way to bridge the gap. I had a bluetooth GPS receiver I
used before with my Wing, but the charger cable frayed and finally
broke. So I'm looking at maybe providing NMEA data over a bluetooth
COM port from the G1. If I can figure out how to do it. So any help is
greatly appreciated, and I will gladly release anything I come up with
back to the community for the minority who might find a use for the
app.

In preparation I have installed Eclipse and the latest Android SDK,
also completed the Hello Android tutorial, but still have little
understanding of how to do more "practical" work. I know from toying
with Visual Studio that Microsoft provided an amazing "WYSIWYG" IDE,
but the Android/Eclipse combo sure doesn't make developing THAT easy.

Thanks in advance.
Matt

--~--~---------~--~----~------------~-------~--~----~

3. Manage groups on G1/ADP1 - Android OS

4. Image cropping in SDK 1.1

5. R class not created or updating in Eclipe

6. need help in getting screen coordinates of a view

7. Android SDK for 64 bit Linux?