Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How change the background color of focussed view

Tags:

android

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;
        }});
like image 732
ngesh Avatar asked May 20 '11 05:05

ngesh


1 Answers

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

like image 116
Tek Yin Avatar answered Nov 08 '22 06:11

Tek Yin