android checkboxpreference属性,android – 具有自己布局的CheckBoxPreference

我有PreferenceScreen和一些PreferenceCheckBoxes.我想更改textColor和textSize的标题和摘要以及CheckBox的图像选中和取消选中.所以我使用android:layout来改变这个属性.

我的ChceckBoxPreference:

android:layout="@layout/preference_checkbox"

android:key="temp"

android:title="@string/title"

android:summary="@string/summary"

android:defaultValue="true"

/>

当我使用android:widgetLayout时,它看起来很奇怪.这是我的preference_checkbox.xml:

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp"

>

android:orientation="vertical"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_alignParentLeft="true"

android:layout_marginLeft="10dp"

>

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

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textColor="@color/gray"

android:textSize="20sp"

/>

android:id="@+android:id/summary"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textColor="@color/gray"

android:textSize="14sp"

/>

android:id="@+android:id/checkbox"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_alignParentRight="true"

android:layout_marginRight="10dp"

/>

标题为id @ android:id / title和摘要,@ android:id / summary显示正确的值.然而,尽管默认值和id @ android:id / checkbox复选框无法正常工作.它没有显示正确的值,我无法更改首选项中保留的值.

不使用任何布局,我可以通过触摸整个CheckBoxPreference来更改复选框的值.但现在(使用我的布局)我只能通过触摸此复选框来更改复选框的值.

如何以正确的方式为所有功能制作CheckBoxPreference的布局?

解决方法:

试试这个为preference_checkbox.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="#FF0000" />

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" />

标签:android,android-preferences,checkboxpreference

来源: https://codeday.me/bug/20190928/1828194.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值