如何在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"

>

转载于:https://www.cnblogs.com/Xiegg/p/3811392.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值