步骤一:在使用的ListView的activiey里使用android:theme=“@style/Theme的名字”
步骤二:创建Themes.xml 在Themes.xml里定义的使用的样式。如:
步骤三:在themes.xml使用了styles.xml定义的listView的属性,创建styles.xml.在styles.xml里定义listView的样式,在listView的样式里面能够使用图片,或者自定义的xml文件。通过这一系列的步骤,就能形成自己的ListView的样式了。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="cn.hrbb"
4 android:versionCode="1"
5 android:versionName="1.0">
6 <uses-sdk android:minSdkVersion="8" />
7
8 <application android:icon="@drawable/icon" android:label="@string/app_name">
9 <activity android:name=".TestActivity"
10 android:label="@string/app_name" android:theme="@style/mainTheme">
11 <intent-filter>
12 <action android:name="android.intent.action.MAIN" />
13 <category android:name="android.intent.category.LAUNCHER" />
14 </intent-filter>
15 </activity>
16
17 </application>
18 </manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="mainTheme" parent="android:Theme">
<item name="android:listViewStyle">@style/Widget.ListView</item>
<item name="android:listDivider">@android:color/transparent</item>
<item name="android:scrollbarThumbVertical">@drawable/scrollbar_handle_vertical</item>
<item name="android:scrollbarTrackVertical">@drawable/scrollbar_vertical</item>
</style>
</resources>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="UTF-8"?>
2 <selector xmlns:android="http://schemas.android.com/apk/res/android">
3 <item android:state_window_focused="true" android:state_focused="false" android:drawable="@drawable/btn_default_normal"/>
4 <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/btn_default_pressed" /> <!-- pressed -->
5 <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/btn_default_selected" /> <!-- focused -->
6 <item android:drawable="@drawable/btn_default_normal" /> <!-- default -->
7 </selector>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3 <style name="Widget" ></style>
4 <style name="Widget.AbsListView">
5 <item name="android:scrollbars">vertical</item>
6 <item name="android:fadingEdge">vertical</item>
7 <item name="android:scrollbarStyle">outsideInset</item>
8 </style>
9
10 <style name="Widget.ListView" parent="Widget.AbsListView">
11
12 <item name="android:listSelector">@drawable/btn_default</item>
13 <item name="android:divider">@android:color/transparent</item>
14 </style>
15 </resources>
通过以上的文件,直接使用ListView就能形成自己ListView的风格了。
效果