My code is :
ListContacts.java
publi
try this
listViewContactList.setOnFocusChangeListener(new OnFocusChangeListener(){
@Override
public void onFocusChange(View v, boolean hasFocus) {
v.setBackgroundColor(Color.BLACK);
ImageView img=(ImageView)v.findViewById(R.id.callimage);
img.setImageResource(R.drawable.yourimage);
TextView tv=(TextView)v.findViewById(R.id.your_textview_id);
tv.setBackgroundResource(R.drawable.your_back);
}
});
in getView
if(position == focusedPosition) {
textView.setColor(context.getResources().getColor(R.color.color_for_focused_item);
} else {
textView.setColor(context.getResources().getColor(R.color.color_for_normal_item);
}
Add an xml file to manage the background of the LinearLayout.
list_bg_selector.xml :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active tab -->
<item android:state_selected="true" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/list_selected_bgimage" />
<!-- Inactive tab -->
<item android:state_selected="false" android:state_focused="false"
android:state_pressed="false" android:drawable="@drawable/list_default_bgimage" />
<!-- Pressed tab -->
<item android:state_pressed="true" android:drawable="@drawable/list_selected_bgimage" />
<!-- Selected tab (using d-pad) -->
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/list_selected_bgimage" />
</selector>
To manage the text color, set the text color to another xml.
text_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@android:color/black"/>
<item android:state_focused="true" android:color="@android:color/black"/>
<item android:state_pressed="true" android:color="@android:color/black"/>
<item android:color="@android:color/white"/>
</selector>