android - Changing background color of a selected List item -


i have menu drawer list has custom arrayadapter. wish change background color of selected list item i'm not sure how to. tried changing in getview of adapter, how others have suggested, didn't work, background color still unchanged.

here's tried:

public view getview(int position, view convertview, viewgroup parent) {   view myview = getitem(position).getview(minflater, convertview);   if (myview.isselected())     myview.setbackgroundcolor(color.black);   return myview; } 

where should doing this, , how?

thanks.

you can using selector below...

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">      <item android:drawable="#ffffff" android:state_activated="false"/>     <item android:drawable="#000000" android:state_pressed="true"/>     <item android:drawable="#000000" android:state_activated="true"/>  </selector> 

and use selector background of list item layout below...

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="48dp"      android:background="@drawable/list_selector">      ........     ........  <relativelayout/> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -