为什么我无法显示默认的android行选择颜色?

时间:2011-11-21 13:13:09

标签: java android android-listview

我正在使用此代码实现ListView部分:

  public class ListSample extends ListActivity implements OnItemClickListener{   

    public final static String ITEM_TITLE = "title";   
    public final static String ITEM_CAPTION = "caption";   
    public Resources resources;
    public static Uri path;
    ImageAdapter customAdapter;
    private SeparatedListAdapter adapter;
    public static File file;
    public static ProgressDialog  m_progressDialog;
    public static ListView list;

    @Override  
    public void onCreate(Bundle icicle) {   
        super.onCreate(icicle);  
        setContentView(R.layout.main);

        // create our list and custom adapter   
        adapter = new SeparatedListAdapter(this); 

       // customAdapter =new ImageAdapter(ListSample.this, R.layout.list_item,mList);

        adapter.addSection("Local documents:", new ArrayAdapter<String>(this,   
            R.layout.list_item, new String[] { "WindowsONE Mobile PK", "WindowsorONE Moldings","Filet for a burger video" }));
        adapter.addSection("Non-local resources:", new ArrayAdapter<String>(this,   
                R.layout.list_item, new String[] { "Launch Photo slideshow link", "Dealer locator link" }));
        adapter.addSection("Send emails:", new ArrayAdapter<String>(this,   
                R.layout.list_item, new String[] { "Send Dealer Locator email", "Send Catalog email","Send install instrucation link" })); 
        //For extra Information in Listview    
        //adapter.addSection("Non-local resources:", new SimpleAdapter(this, security, R.layout.list_complex,   
        //new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption }));        
        list = getListView();
        list.setAdapter(adapter);   
        list.setTextFilterEnabled(true);
        list.setOnItemClickListener(this); 
       }
}

如果我运行此应用程序,一切正常。
但是当选择任何行时动作完成但是我无法看到任何高亮颜色,就像选择了这一行一样(就像默认的android行选择颜色一样)。

那么,我应该做些什么才能实现呢?

我想在选择特定行时显示高亮颜色。

2 个答案:

答案 0 :(得分:1)

如果您使用自定义背景进行行布局 - 您必须自己制作高光动画。您可以使用选择器布局

执行此操作
    <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item 
        android:state_pressed="false"
        android:drawable="@drawable/btn_back"
        >

       </item>
    <item 
        android:state_pressed="true"
        android:drawable="@drawable/btn_back_tap"
        >          
    </item>

</selector>

答案 1 :(得分:1)

您的rowitem.xml必须具有背景颜色。删除它,您将看到默认的高亮颜色。如果要自定义突出显示,请使用选择器作为flybirdx建议