防止在列表视图中突出显示

时间:2011-07-16 02:40:28

标签: android listview highlight

我有一个列表视图,我想阻止选择时突出显示。背景颜色在列表视图行布局上设置为半透明。我做得越透明,它在Android默认的橙色中突出显示的越多。

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/CodeFont"
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="35sp" 
    android:gravity="center_vertical"
    android:checkMark="?android:attr/listChoiceIndicatorSingle"
    android:paddingLeft="20dip" 
    android:paddingTop="10dip" 
    android:paddingBottom="10dip"
    android:cacheColorHint="#00000000" 
    android:background="#AAEBD5A8"

/>

如果我删除背景并设置这样的颜色,

private void makeListDefault(ListView listView) {
    int childCount = listView.getChildCount();
    int i = 0;
    for (i = 0; i < childCount; i++) {
        View view = listView.getChildAt(i);
        view.setBackgroundResource(R.drawable.hilight_no_gradient_correct_drawable);
    }
}

它不会以任何方式影响颜色。 hilight_no_gradient_correct_drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FF98FB98" android:endColor="#FF98FB98"
        android:angle="90" />
        <!-- 98FB98 is a shade of green -->
</shape>

有什么想法吗?我也尝试过选择器,但似乎没有任何影响颜色。

2 个答案:

答案 0 :(得分:1)

您可以将listSelector定义为Transparent:

android:listSelector="@android:color/transparent"

它将阻止突出显示/选定状态的默认颜色。

答案 1 :(得分:0)

您是否尝试使用自定义颜色作为ListView的背景项?

<ListView
    android:id="@+id/conversations"
    android:scrollbars="vertical"
    android:layout_width="fill_parent"
    android:cacheColorHint="#000000"
    android:visibility="visible"
    android:listSelector="@color/backgroundlistcell"
    android:dividerHeight="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1">
</ListView>

请注意listSelector =“....”

backgroundlistcell.xml

<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:state_focused="false"
    android:state_pressed="false"
    android:state_selected="false"
    android:state_enabled="true"
    android:drawable="@drawable/listcell_enabled" />
<item
    android:state_focused="true"
    android:drawable="@null" />
<item
    android:state_selected="true"
    android:drawable="@null" />
<item
    android:state_pressed="true"
    android:drawable="@drawable/listcell_pressed" />
</selector>

也许您需要更改可绘制的属性值,但这应该有效。

相关问题