如何在android中利用Theme设置application 的所有listview的style?~

今天看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"

>

posted @ 2014-06-27 10:14  crowinhell  阅读(819)  评论(0编辑  收藏  举报