標籤:android style color 檔案 io cti
今天看VLC的原始碼,發現一個很神奇的東西
所有listview的點擊效果背景色都是橘黃色
花了點時間找了一下看看怎麼實現的。
首先,定義一個<selector>
like this:
<selector>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/orange">
</shape>
</item>
</selector>
當然,你也可以直接找一張橘黃色的圖片,效果和上面是一樣的
然後你可以建一個style,這個style可以包含你希望的listview的所有屬性,這裡只舉例說明,所以唯寫了一個android:listselector
<style name="theme.list">
<item name="android:listselector">@drawable/一張圖片 or 上面那個selector對應的xml,放在drawable檔案夾下即可~ </item>
</style>
把這個style放到大的theme定義中,like this:(紅字表示繼承,因為畢竟我們只修改了一個大的theme中的一部分)
<style name="Theme.APPLICATION" parent="Theme.sherlock.Light">
<item name="listviewStyle">@style/theme.list</item>
</style>
最後把這個theme放到你的activity的android:theme中,這樣你的那個activity所有的listview(包括子fragment)都是這個style 了~
<Activtiy
android:theme="@style/Theme.APPLICATION"
>