I am not sure if this is possible. I have this button:
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="45px"
android:drawableTop="@drawable/buttontv"
android:layout_weight="1"
android:background="@null"
android:textColor="#ffffff"
android:textSize="9px"
android:text="TV"/>
And this button has this xml element:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/tv" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/tv_pressed" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/tv_pressed" />
<item
android:drawable="@drawable/tv" />
</selector>
And in my application, I use this code to click a button:
OnClickListener b1Listener = new OnClickListener(){
@Override
public void onClick(View v) { loadUrl("http://example.org/"); v.setPressed(true); }
};
Button b1 = (Button) findViewById(R.id.b1);
b1.setOnClickListener(b1Listener);
What I would like, when I clicked the button, drawableTop sets one of the elements with the @ drawable / tv_pressed attribute - and remains there (as in "this is the current active button").
I tried adding v.setPressed (true) to the onClick function (since that is all I could find on Google), but that did not work.
Can this be done? Or is there a better alternative to what I'm trying to accomplish?
Repox source
share