android listview custom style 自定义样式

1. xml下listView
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
style="@style/Activity_ListView_Specfication"
>
</ListView>
2.style.xml
<style name="Activity_ListView_Specfication" parent="android:Widget.ListView.White">
<item name="android:background">#FFF</item>
<item name="android:cacheColorHint">#FFF</item>
<item name="android:divider">#BBB</item>
<item name="android:dividerHeight">1px</item>
<item name="android:listSelector">@drawable/specfication_listview_style</item>
</style>
3.drawable文件夹下specfication_listview_style.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="false">
<shape>
<solid
android:color="#FFFFFF" />
</shape>
</item>
<item
android:state_focused="false">
<shape>
<solid
android:color="#FFFFFF" />
</shape>
</item>
<item>
<shape>
<solid
android:color="#FFFFFF" />
</shape>
</item>
</selector>
4.代码里给listView加样式 。如下
ExpandableListView listView = new ExpandableListView(this);
listView.setSelector(getResources().getDrawable(
R.drawable.specfication_listview_style));

你可能感兴趣的:(移动开发)