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?

enter image description here

first of all, need know background settings functions of view, change background-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

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -