I have a linear layout that contain the following listview :
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="#FF0000"
android:dividerHeight="4dp"
/>
and the layout is used by a ListActivity, the issue is that the following line in ListView xml doesn't take effect :
android:divider="#FF0000"
android:dividerHeight="4dp"
and the default divider is set. Do you why this happening and how to fix it?
its an difference of the dp and px.
use this
android:dividerHeight="4px"
instead of
android:dividerHeight="4dp"
and use this also if you want
int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);
you will get it..
For me this is working perfectly:
<ListView
android:id="@+id/listHomeScreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#000"
android:divider="#7F7F7F"
android:dividerHeight="1dip"
android:listSelector="@android:color/transparent" >
</ListView>
Ensure we are not overriding android:dividerHeight or divider color.
There is bug in Android Lollipop 5.0 if you have overridden setEnabled() then this happens. Check ot this question for more info ListView divider not showing in Android 5
Its resolved now . the issue is before i decide to make the list in xml i had this code in my listActivity to add divider which was overriding the xml :
int[] colors = { 0xA8A8A8A8, 0xFFFFFFFF, 0xA8A8A8A8 };
getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
getListView().setDividerHeight(1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.