我想更改ListView
分隔線的顏色。任何幫助,將不勝感激。如何更改Android ListView分隔線的顏色?
回答
您可以使用android:divider="#FF0000"
在佈局xml文件中設置此值。如果您要更改顏色/繪圖,則必須設置/重置分隔線的高度。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#FFCC00"
android:dividerHeight="4px"/>
</LinearLayout>
或者你可以編寫它:
int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);
希望它可以幫助
完美,我的物品是在一個紅色的漸變背景,你的效果使他們宏偉! – Darkendorf 2012-12-21 07:44:08
如果你擴展ListActivity,用getListView()替換mylist() – Aziz 2014-04-24 14:40:43
對於單一色線使用:
list.setDivider(new ColorDrawable(0x99F10529)); //0xAARRGGBB
list.setDividerHeight(1);
是DividerHeight之後的設置是非常重要的除法器,否則你不會得到任何東西。
謝謝,我在setDivider()之前調用了setDividerHeight(),並且沒有顯示分隔符。 – 2012-08-24 14:42:28
對操作順序非常有幫助的評論。我只花了2個小時試圖讓它工作。漂亮的設計,Android。 – 2014-07-10 09:52:26
您也可以通過從你的資源的顏色:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
使用android:divider="#FF0000"
和android:dividerHeight="2px"
的ListView控件。
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>
XML版本@Asher Aslan酷效果。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="180"
android:startColor="#00000000"
android:centerColor="#FFFF0000"
android:endColor="#00000000"/>
</shape>
名稱爲形狀:繪製文件夾下list_driver.xml
<ListView
android:id="@+id/category_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_driver"
android:dividerHeight="5sp" />
有兩種方法做同樣的:
你可以設置了Android的價值:divider =「#FFCCFF」 in layout xml file。 有了這個你也必須指定這樣的分隔線的高度android:dividerHeight =「5px」。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lvMyList" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="#FFCCFF" android:dividerHeight="5px"/> </LinearLayout>
您還可以通過編程方式做到這一點...
ListView listView = getListView(); ColorDrawable myColor = new ColorDrawable( this.getResources().getColor(R.color.myColor) ); listView.setDivider(myColor); listView.setDividerHeight();
使用下面的代碼在XML文件中
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dp">
</ListView>
最好解釋一下爲什麼你的解決方案有效。只回答代碼可能會解決問題,但這並不一定回答提問者的問題。 – SuperBiasedMan 2015-05-15 10:03:18
- 1. 更改LinearLayout中分隔線的顏色
- 2. 在Android中更改分隔線的顏色
- 3. 如何更改操作欄的分隔線顏色?
- 4. 如何更改顏色UINavigation欄的分隔線
- 5. 更改分隔線顏色Android DatePicker對話框
- 6. 如何更改Android中TabWidget分隔線的顏色和/或可繪製?
- 7. 如何更改警報對話框標題分隔線顏色android
- 8. 如何更改jQuery Mobile Listview的顏色
- 9. 如何更改ListView的字體顏色
- 10. ListView分隔線的默認顏色是什麼?
- 11. 如何更改ListView的顏色,交替排列顏色?
- 12. 在ListView中更改顏色
- 13. 在ListView中更改顏色
- 14. 如何在Android中更改Listview項目的顏色和文本顏色
- 15. 動態更改UITableView單元格分隔線顏色
- 16. 如何在ListView android中更改特定的行/行顏色?
- 17. 如何更改微調控件的邊框和分隔線顏色
- 18. 如何更改Microsoft Chart Controls中的軸分隔線顏色(柱形圖)
- 19. iOS:如何更改UISplitViewController中分隔符的顏色?
- 20. 如何更改匹配分隔符的vimtex高亮顏色?
- 21. 如何更改vscode中的滾動條分隔符顏色?
- 22. 如何更改背景線的顏色,結構的顏色
- 23. Android Listview:如何更改xml中的字體樣式和字體顏色?並在xml中顯示分隔符
- 24. 如何更改Android中的seekbar顏色?
- 25. 如何更改fab:tit_title顏色的FloatingActionButton android
- 26. 如何更改UIImage部分的顏色?
- 27. 如何更改seaborn線條顏色lmplot
- 28. 在簡單ListView中更改ListView文本顏色 - Android
- 29. Android改變線程顏色
- 30. 如何更改Android中EditText的底線顏色?
你也應該能夠指定一個' 'android:divider'中的Drawable資源也是如此。現有的分頻器是一個漸變。 – CommonsWare 2010-03-03 16:27:53
哪裏是現有的梯度分配器? – ninjasense 2010-10-21 21:52:38
如果你在XML中使用它,請確保使用android:dividerHeight查看高度,否則你將無法獲得線條 – 2011-06-28 22:57:01