2011-07-16 37 views
0

我有一個列表視圖,我想要防止突出顯示選擇。背景顏色在列表視圖行佈局上設置爲半透明。透明度越高,它在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> 

任何想法?我也試過用選擇器,但似乎沒有影響顏色。

回答

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> 

也許你會需要改變繪製屬性值,但這應該工作。

+0

謝謝,我試過了,包括與選擇器作爲android:listSelector =「@ background/backgroundlistcell」從ListActivity佈局和列表項目佈局,但它似乎使項目完全透明,無論透明度和我用過的顏色。這可能會影響到我的代碼中的某些內容,因爲我正在從中突出顯示等等。但是,我無法得到這個工作。 –

1

您可以定義listSelector一樣透明:

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

這將避免對高亮/選擇狀態的默認顏色。