我想禁用当触摸listView行时出现的橙色高亮。到目前为止,在我的xml我已经尝试了以下:

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

更多信息:我希望当用户在这个listView对象上触摸屏幕时,没有任何差异。


当前回答

对于我android:focusableInTouchMode="true"是去的方式。android:listSelector="@android:color/transparent"没有用。注意,我使用的是一个自定义的列表视图,每行都有一些对象。

其他回答

在虚拟和真实设备上进行了一些“谷歌”测试后,我注意到下面的代码是有效的:

ArrayAdapter<String> myList = new ArrayAdapter<String>(this, R.layout.list_item, strText) {
    public boolean isEnabled(int position) 
    { 
            return false; 
    } 
};

注意,我省略了areAllItemsEnabled()部分。

从ListView禁用焦点高亮,

当你设置你的ListAdapter使用下面的代码

ListAdapter adapter = new SimpleCursorAdapter(MyList, Layout, c, 
                new String[] { "Name", "Score" }, to) 
{ 
    public boolean areAllItemsEnabled() 
    { 
        return false; 
    } 
    public boolean isEnabled(int position) 
    { 
        return false; 
    } 
}; 

这将覆盖BaseAdapter类。它还取消了单元格之间的白色边界。

你可以从onItemClick中获得pos 和做的事:

listView.setItemChecked(pos, false);

这是我知道的最好的方法

作为替代:

listView.setSelector(android.R.color.transparent);

or

listView.setSelector(new StateListDrawable());

对于我android:focusableInTouchMode="true"是去的方式。android:listSelector="@android:color/transparent"没有用。注意,我使用的是一个自定义的列表视图,每行都有一些对象。