本文介绍了定制复选框preference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法定义我的复选框,虽然我已经定义了XML preference文件的背景,它不拉文件。1.我想显示自定义图像复选框,并定义选择XML作为android_button.xml它看起来像:

I am unable to customize my checkbox , although I have defined the background in the xml preference file, it doesn't pull the file.1. I am trying to display custom images for checkbox and have defined the selector xml as "android_button.xml" which looks like :

   <?xml version="1.0" encoding="utf-8"?>
  <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checkable="true"
      android:drawable="@drawable/state_normal" /> <!-- pressed -->
<item  android:state_checked="true"
      android:drawable="@drawable/android_pressed" /> <!-- focused -->
<item android:drawable="@drawable/state_normal" /> <!-- default -->
</selector>

state_normal和android_ pressed两种。PNG图像清晰度>绘制文件夹。

state_normal and android_pressed are two .png images in res>drawable folder.

2.my复选框preference.xml文件是:

2.my Checkbox preference.xml file is :

          <CheckBoxPreference android:key="@string/Drop_Option"
            android:title="Close after call drop"
            android:defaultValue="true"
            android:background="@drawable/android_button"
            />

有没有在定义中的任何错误,这显示在屏幕上的唯一变化是android:标题文字,如果我改变了文本,它改变了文字。没有别的变化。我该如何解决这个问题。谢谢您的建议。

Is there any error in the definition, The only change that shows up in screen is the android:title text, if I change the text, it changes the text. Nothing else changes. How do I fix this. Thank you for your suggestion.

推荐答案

有两种方式来实现你所需要的,首先是在资源定义自定义复选框布局custom_chexbox.xml /布局:

There are two ways to achieve what you need, first is to define custom checkbox layout custom_chexbox.xml at res/layout:

<?xml version="1.0" encoding="UTF-8"?>
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+android:id/checkbox" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:focusable="false"
android:clickable="false" android:button="@drawable/android_button"/>

然后,你需要指定布局为preference:

Then you need to specify this layout for the preference:

<CheckBoxPreference android:key="@string/Drop_Option"
 android:title="Close after call drop" android:defaultValue="true"
 android:widgetLayout="@layout/custom_checkbox"/>

第二种方法是创建一个自定义主题,重新定义样式复选框意见和应用主题,以preferences活动,见http://stackoverflow.com/questions/3491203/how-to-customize-the-color-of-the-checkmark-color-in-android-in-a-dialog-andr/3491314#3491314了解详细信息。

这篇关于定制复选框preference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 03:51
查看更多