Android - I set a custom background for a listView, and the highlight has gone -
ok, simpleadapter's getview function:
@override public view getview(int position, view convertview, viewgroup parent) { view view = super.getview(position, convertview, parent); view.setbackgroundcolor(r.drawable.color1); return view; } }
and color1.xml file, in res/drawable-lpi folder:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:color="#ffff00ff"/> <!-- pressed --> <item android:state_selected="true" android:color="#ff0000ff"/> <!-- selected --> <item android:state_focused="true" android:color="#ff0000ff"/> <!-- focused --> <item android:color="#ffffffff"/> <!-- default --> </selector>
why still this?
first of all, need know background settings functions of view, change background-drawable.
- the setbackgroundcolor creates colordrawable.
- the setbackgroundresource loads drawable resource
- the setbackgrounddrawable, obviously, uses drawable.
when call setbackgroundcolor highlight.xml, try create colordrawable value of generated id of r.drawable.highlight.
you need call setbackgroundresource method, equivalent "android:background" xml tag.
your highlight.xml state-list, instance of statelistdrawable. if wanted change colors, use color-state-list.
Comments
Post a Comment