I want to set the ListView style in the Theme, so that all the ListView of the Application will inherit the style. My code looks like this:
style.xml
<!-- Light Theme of the Application -->
<style name="AppTheme.Light" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">@style/ActionBar.Green</item>
<item name="android:absListViewStyle">@style/AbsListViewStyle.Light</item>
</style>
<style name="AbsListViewStyle.Light" parent="android:style/Widget.AbsListView">
<item name="background">@color/background_light</item>
<item name="android:divider">@color/light_gray</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:listSelector">@drawable/actionbar_background_green</item>
<item name="android:drawSelectorOnTop">false</item>
<item name="android:cacheColorHint">#00000000</item>
</style>
I set the theme of the Activity in the AndroidManifest.xml. But it seems that the style is not applied to the ListView. Why is that?
Finally I got the reason, I should use android:listViewStyle attribute instead of absListViewStyle:
style.xml
<!-- Light Theme of the Application -->
<style name="AppTheme.Light" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">@style/ActionBar.Green</item>
<item name="android:listViewStyle">@style/ListViewStyle.Light</item>
</style>
<style name="ListViewStyle.Light" parent="android:style/Widget.ListView">
<item name="background">@color/background_light</item>
<item name="android:divider">@color/light_gray</item>
<item name="android:dividerHeight">1dp</item>
<item name="android:listSelector">@drawable/actionbar_background_green</item>
<item name="android:drawSelectorOnTop">false</item>
<item name="android:cacheColorHint">#00000000</item>
</style>
In this way I can apply ListView style in the Theme xml.
You need to set it on your ListView in xml for list view add:
style="@style/AbsListViewStyle.Light"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With