我有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

android checkboxpreference属性,android – 具有自己布局的CheckBoxPreference相关推荐

  1. android preference属性,Android进阶——Preference详解之Preference系的基本应用和管理(二)...

    并非我们第一次打开相应界面之后就会自动创建对应的SharedPreferences文件,而是在我们改变了原有状态时候喎�"/kf/ware/vc/" target="_b ...

  2. android layout_width 属性,android:layout_weight属性详解

    在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...

  3. android videoview属性,Android VideoView无法播放视频错误,特别是.mp4

    @H_502_1@我正在尝试在我的应用程序中播放视频,但我得不能播放此视频错误.关于这一点,我遇到了很多线索.他们要求在玩家准备好后开始播放视频.我也是这样做的.但无法弄清楚问题.请在下面找到我的代码 ...

  4. android videoview属性,Android VideoView

    VideoView,用于播放一段视频媒体,它继承了SurfaceView,位于"android.widget.VideoView",是一个视频控件. 既然是播放一段视频,那么不可避 ...

  5. 没有android:padding属性,android pading的四个值,为负值时,什么情况下,有效啊

    在我的理解中, 设置 padding 为负值和设置为0在显示上不会有什么区别, 所以, 你想要的效果是什么? OK, 之前没有自习考虑这个问题, 现在帮你分析一下. 首先, 从 xml 中解析 pad ...

  6. 没有android:padding属性,android自定义无上下padding的textview

    因为工作需要需要无上下padding的textview,经过查阅资料,很多说xml中的配置includefontpadding=false,但无法实现0 padding的需要. 也有说通过设置负数的m ...

  7. android应用开发---(第1章)android基础学习之六大Layout布局

    Android中任何可视化的控件都是从android.veiw.View继承而来的,系统提供了两种方法来设置视图:第一种也是我们最常用的的使用XML文件来配置View的相关属性,然后在程序启动时系统根 ...

  8. Android 自定义控件属性

    前言 自定义控件经常需要一些特殊的配置,添加一些自定义属性. 1. 自定义属性 attrs.xml文件,所有自定义属性需要在文件中添加declare-styleable节点来声明,例如定义属性back ...

  9. Android知识补充(Android学习笔记)

    Android知识补充 ●国际化 所谓的国际化,就是指软件在开发时就应该具备支持多种语言和地区的功能,也就是说开发的软件能同时应对不同国家和地区的用户访问,并针对不同国家和地区的用户,提供相应的.符合 ...

  10. android @style/name,android style和attr的用法

    一  .对style和attr的引用 1. 当引用平台的style做为style的parent时,[email protected]:style/主题" == [email protecte ...

最新文章

  1. iOS中KVO模式的解析与应用
  2. Android -- 消息处理机制源码分析(Looper,Handler,Message)
  3. 第十六 django进一步了解
  4. 后台给前台服务器控件添加样式
  5. 326. Power of Three
  6. ubuntu20.04运行《大航海家2》
  7. eclipse和Tomcat绑定
  8. java 线程由浅入深_由浅入深,Java 并发编程中的 Synchronized(一)
  9. center.php,mycenter.php
  10. Android手势的识别
  11. oracle jinitiator版本太旧,Windows7系统运行java软件提示Oracle JInitiator版本太旧怎么办...
  12. gis数据与cad数据转换之间的关系
  13. 怎样转移计算机系统用户文件,巧用“个人文件转移工具”一键转移系统盘的用户文件夹...
  14. java毕设项目——图书借阅管理系统(附源码课件)
  15. 2007年日历带农历表_2007年农历阳历表 2007年农历表 2007年日历表
  16. 用java设计一个三角形类_利用Java类库中的Point类设计一个三角形类,编程求三角形面积...
  17. PCB后续以及泪滴、敷铜和标识
  18. IDEA 自定义代码模板
  19. genymotion 安装
  20. 【前端css】如何实现分隔线效果(css兄弟兄弟节点样式+ ~)

热门文章

  1. 面试题:Java多线程
  2. java jshell_[Java JShell 指南] - 介绍
  3. 将iTunes音乐传输到USB驱动器以在汽车中收听
  4. ENVI5.4中Himawari-8数据处理(向日葵8号卫星H-8)
  5. 奇妙“水仙花数”的判断
  6. 6678学习笔记开篇
  7. Facebook 数字货币:缘起、意义和后果
  8. 热力地图高德_《高德地图》城市热力图开启查看方法
  9. 正则判断手机号地区_手机号码验证方法(正则验证)
  10. PHP 框架集成使用 UEditor 编辑器的方法