android preference-headers 字体颜色,如何修改CheckBoxPreference 中title ,summary字体的颜色...

以前没怎么关注过PreferenceActivity的一些用法只是简单了解下,然后刚好今天遇到了某个机型上出现了问题:我明明设置的是黑色的字体,在这个机器上却是白色的,然后各种摸索得出了个推论,页面的字体颜色什么的,可能是更随系统来的,受系统调控:

我是这么写的,

android:defaultValue="true"

android:key="weather_use_metric"

android:textColor="@color/black"

android:title="@string/weather_use_metric" />

问题出现 了那没办法,只能想办法改了,好在现在学会了面向google编程,然后搜的一下,找到了个解决方案,先上怎么解决,然后再说为什么这么干。首先建个layout ,名字随便取(我取名custom_preferece_layout.xml),内容如下:

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:minHeight="?android:attr/listPreferredItemHeight"

android:gravity="center_vertical"

android:paddingRight="?android:attr/scrollbarSize">

android:layout_height="wrap_content" android:layout_marginLeft="15dip"

android:layout_marginRight="6dip"

android:layout_marginTop="6dip"

android:layout_marginBottom="6dip"

android:layout_weight="1">

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:singleLine="true"

android:textAppearance="?android:attr/textAppearanceLarge"

android:ellipsize="marquee" android:fadingEdge="horizontal"

android:textColor="@color/black" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@android:id/title"

android:layout_alignLeft="@android:id/title"

android:textAppearance="?android:attr/textAppearanceSmall"

android:maxLines="4" />

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:gravity="center_vertical" android:orientation="vertical" />

在这个布局中修改title,sunmmary的颜色就可以了。

然后再CheckBoxPreference 中加一句:

android:defaultValue="true"

android:key="weather_use_metric"

android:layout="@layout/custom_preferece_layout"

android:textColor="@color/black"

/>

然后,就解决了这个问题,那为什么这么搞呢?进入CheckBoxPreference 顶层父类Preference中看,看到构造中的注释了:

1e0890e9d974

QQ截图20161110175559.png

这玩意默认的控制了样式,然后再往下看到一个方法:

1e0890e9d974

QQ截图20161110175911.png

他说大部分情况足够用了,但是这不是出来问题么,于是到android的values中的attr下找,

1e0890e9d974

Paste_Image.png

嗯很贴心,行数都截出来了。顶层默认实现了个布局,在CheckBoxPreference的onBindView方法中出现了个id和一个方法:

1e0890e9d974

QQ截图20161110181103.png

id点进去能找到个布局,然后再父类TwoStatePreference中可以看到这个方法里面写了什么,注意看上面的布局控件的id,你没看错,就是覆盖了preference_material.xml 中的布局:

1e0890e9d974

QQ截图20161110181315.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值