android– 具有自己布局的CheckBoxPreference

android– 具有自己布局的CheckBoxPreference,第1张

概述我有PreferenceScreen和一些PreferenceCheckBoxes.我想更改textColor和textSize的标题和摘要以及CheckBox的图像选中和取消选中.所以我使用android:layout来改变这个属性.我的ChceckBoxPreference:<CheckBoxPreferenceandroid:layout="@layout/preference_checkbox"andr

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

我的ChceckBoxPreference:

<CheckBoxPreference    androID:layout="@layout/preference_checkBox"    androID:key="temp"    androID:title="@string/Title"    androID:summary="@string/summary"    androID:defaultValue="true" />

当我使用androID:WidgetLayout时,它看起来很奇怪.这是我的preference_checkBox.xml:

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="horizontal"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent"    androID:padding="10dp"><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:orIEntation="vertical"    androID:layout_wIDth="wrap_content"    androID:layout_height="fill_parent"    androID:layout_alignParentleft="true"    androID:layout_marginleft="10dp"><TextVIEw     androID:ID="@+androID:ID/Title"    androID:layout_wIDth="fill_parent"     androID:layout_height="wrap_content"     androID:textcolor="@color/gray"    androID:textSize="20sp"         /><TextVIEw     androID:ID="@+androID:ID/summary"    androID:layout_wIDth="fill_parent"     androID:layout_height="wrap_content"     androID:textcolor="@color/gray"    androID:textSize="14sp"    /></linearLayout><CheckBox    androID:ID="@+androID:ID/checkBox"    androID:layout_wIDth="wrap_content"     androID:layout_height="fill_parent"     androID:layout_alignParentRight="true"    androID:layout_marginRight="10dp"/>  </relativeLayout>     

标题为ID @ androID:ID / Title和摘要,@ androID:ID / summary显示正确的值.然而,尽管默认值和ID @ androID:ID / checkBox复选框无法正常工作.它没有显示正确的值,我无法更改首选项中保留的值.
不使用任何布局,我可以通过触摸整个CheckBoxPreference来更改复选框的值.但现在(使用我的布局)我只能通过触摸此复选框来更改复选框的值.
如何以正确的方式为所有功能制作CheckBoxPreference的布局?

解决方法:

试试这个为preference_checkBox.xml

<?xml version="1.0" enCoding="utf-8"?><!-- copyright (C) 2006 The AndroID Open Source Project licensed under the Apache license, Version 2.0 (the "license"); you may not use this file except in compliance with the license. You may obtain a copy of the license at http://www.apache.org/licenses/liCENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd. See the license for the specific language governing permissions and limitations under the license. --><!-- Layout for a Preference in a PreferenceActivity. The Preference is able to place a specific Widget for its particular type in the "Widget_frame" layout. --><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="match_parent" androID:layout_height="wrap_content"androID:minHeight="?androID:attr/ListPreferredItemHeight"androID:gravity="center_vertical" androID:paddingRight="?androID:attr/scrollbarSize"><relativeLayout androID:layout_wIDth="wrap_content"    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">    <TextVIEw androID:ID="@+androID:ID/Title"        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" />    <TextVIEw androID:ID="@+androID:ID/summary"        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" /></relativeLayout><!-- Preference should place its actual preference Widget here. --><linearLayout androID:ID="@+androID:ID/Widget_frame"    androID:layout_wIDth="wrap_content" androID:layout_height="match_parent"    androID:gravity="center_vertical" androID:orIEntation="vertical" /></linearLayout>
总结

以上是内存溢出为你收集整理的android – 具有自己布局的CheckBoxPreference全部内容,希望文章能够帮你解决android – 具有自己布局的CheckBoxPreference所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1101446.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存