I want to change the color of the view under focus; in my case it is a table row.
This is my current code, but it doesn't work.
r.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View arg0, MotionEvent arg1) {
{ {
arg0.setBackgroundColor(Color.LTGRAY);
r.setFocusableInTouchMode(true);
}
return false;
}});
You can use XML drawable,
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
create a xml like this
<?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/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
and you need background pic for that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With