[英]Change background color of listview
我在ViewFlipper中使用ListView,如下所示:
<ViewFlipper
android:id="@+Category/viewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="@array/options"
android:cacheColorHint="#FFFFFF"
android:background="#FFFFFF"/>
</ViewFlipper>
我想更改ListView的背景顏色。 我在選項數組中只有5個項目,它們沒有填滿屏幕。 因此,listView的其余部分顯示為默認的灰色。 我想更改此默認顏色。 我在其他與此相關的問題中讀到了關於cacheColorHint屬性的信息。 但這沒有奏效。 誰能幫我這個忙嗎?
提前致謝
將選擇器設置為ListView的背景:
ListView mylw = findViewById(R.id.mylistView);
//Do not use reserved android or java identifiers as your id or variable!
mylw.setBackgroundResource(R.drawable.thexmlbelow);
可繪制:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="Background Color" />
<item android:drawable="Background Color when pressed" />
</selector>
您應該使用layout_height="wrap_content"
(和layout_width="wrap_content"
也如需要)為您的ListView和更改“默認灰色”像你說的通過設置背景ViewFlipper。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.