2012-05-18 103 views
1

我有一個自定義ListView,其中每個row.xml看起來是這樣的:爲什麼當ListView被觸摸時,CheckBox的背景顏色會發生變化?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="bottom" 
android:orientation="horizontal" > 

<CheckBox 
    android:id="@+id/star_listed" 
    style="?android:attr/starStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical" 
    android:contentDescription="@string/question_img_cd" 
    android:focusable="false"/> 

<TextView 
    android:id="@+id/listTitles" 
    style="@style/ListTitles" /> 

當我任何位置上按了ListView,的CheckBox變爲黑色背景,一切工作只是罰款(而不是保持白色)。它發生在我的TextView之前,直到我將它的背景顏色設置爲白色。

row.xml

如果我改變了'CheckBox'背景爲白色,甚至tranparent,它就會消失。

有什麼建議嗎?

+0

http://samir-mangroliya.blogspot.in/p/android-customized-listview.html –

+0

我的自定義'ListView'工作正常。我的鏈接中沒有看到與我的問題相關的任何內容。 – eskalera

回答

1

我不確定,但可能是因爲您使用具有透明背景(我不確定)的恆星的默認樣式屬性(?android:attr/starStyle),並且您看到底層的黑色行顏色。嘗試行中設置的白色父LinearLayout,而不是設置爲行中的每個View的顏色。

+0

你又來了!我將它設置爲'ListView',但不是'LinerLayout'。謝謝。就是這樣。 – eskalera

0

可以在透明設置樣式xml文件的背景複選框上的項目資源(或)設置列表視圖背景色!

歡迎您!

+0

嗨@Dinesh,我的問題是關於「CheckBox」的顏色,它應該在xml屬性上解決。自定義'ListView'的邏輯工作正常。 – eskalera

+0

我在更新答案試試吧! – Dinesh

+0

我已經試過了,就像在我的問題結尾處說的那樣。 – eskalera

相關問題