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. Need Help to use webservices APIs for the following scnerio

Could you please help me with the sample code for the following
scnerio:

- I want to load one url but i want to mask all the contents of that
url. And i have to provide my text boxes and buttons.
- If user clicks My button i have to supply that click action to url
button loaded in webview background to do appropriate action.

For example:
- I have to load gmail.com but i don't want UI of gmail.com. I will
provide my simple UI with username,password and login button.
- If user clicks my UI button i will pass that to gmail.com "login"
button. It has to open the inbox of that particular user without
displaying the login screen of gmail.com

Could you please help which class and APIs i have to use for this
example? Please help me with the sample code...

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

2. TextView.setText doesn't update

I have a Timer set up to update a TextView field once every second.
Thing is, I can't see any changes on screen!

Debugging shows...
setText inside the timer function *is* being called.
getText called on the text view returns the *correct* (new) text that
just isn't displayed!

I've tried TextView.postInvalidate() to no effect.
Code below.

Anyone seen this before?
Thanks.

----------------------------------------------------------------------------------------
IN MyActivity.onCreate:
        mMyTextView = (TextView)this.findViewById
(R.id.txtcurloctitle);

FROM MyTimerTask.Run
        String timeSinceUpdate = tracker.getUpdateAge();
        mMyTextView .setText("Current location (" + timeSinceUpdate +
"):");

IN MyActivity.onOptionsItemSelected:
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Debug");
        msg.setMessage(mMyTextView.getText());
        msg.setPositiveButton("OK", null);
        msg.show();

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

3. How can MapActivity obtain data

4. How to built a resident app ??

5. ListAdapter: View.GONE on some element

6. su permission denied

7. Could not load CSS from local html file. Is functionloadDataWithBaseURL() has some problem or I need to call some other function.