2013-10-12 18 views
0

我已經創建了一個自定義列表視圖,但是當我按下一個項目時,我沒有按下的默認樣式應用於特定的行項目。如何取消激活列表視圖的按下樣式

之前式壓(默認):按下後
enter image description here

風格(按下):我自定義列表視圖的
enter image description here

代碼:

ListView list = (ListView) findViewById(android.R.id.list); 
String items[] = {"cat", "dog", "horse"}; 

list.setAdapter(new myAdapter(items)); 

現在我怎樣才能刪除這些ora幾個地區?通過code

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<item android:state_window_focused="false" android:drawable="@android:color/transparent"/> 

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. --> 
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_disabled_holo_light" /> 
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/list_selector_disabled_holo_light" /> 
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/transparent" /> 
<item android:state_focused="false" android:state_pressed="true" android:drawable="@color/transparent" /> 
<item android:state_focused="true" android:drawable="@drawable/list_focused_holo" /> 

然後設置:

+0

您是否完全想要停用突出顯示或只是擺脫角落處的邊緣? – Skynet

+0

@PirateCube。完全停用 –

+0

請參閱此處:http://stackoverflow.com/questions/6237120/android-disable-listview-selection – Skynet

回答

0

我剛剛將以下內容添加到我的列表視圖中,並解決了我的問題:

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

只需創建一個具有透明色的它可抽拉,像這樣

listView.setSelector(R.drawable.my_transparent_selector); 

XML attribute是:

android:listSelector