Android 为CheckBoxPreference Preference 控件添加样式

article/2025/10/26 17:54:27


        Android 为CheckBoxPreference Preference 控件添加样式

分类: android 8920人阅读 评论(4) 收藏 举报

[html] view plain copy print ?
  1. <CheckBoxPreference   
  2.         android:key="enable_adb"   
  3.         android:layout="@layout/static_background"  
  4.         android:widgetLayout="@layout/accelerometer_checkbox"  
  5.         android:title="@string/enable_adb"   
  6.         android:summary="@string/enable_adb_summary"/>  
  7.   
  8.     <PreferenceCategory  
  9.         android:key="location_category"  
  10.         android:layout="@layout/category_null"  
  11.         android:title="@null" >  
  12.     </PreferenceCategory>  
  13.       
  14.     <Preference  
  15.         android:key="verifier_device_identifier"  
  16.         android:layout="@layout/static_background"  
  17.         android:widgetLayout="@layout/pref_widget_more"  
  18.         style="?android:attr/preferenceInformationStyle"  
  19.         android:title="@string/verifier_device_identifier"  
  20.         android:summary="@string/verifier_device_identifier_not_available"  
  21.         android:persistent="false" />  
  22.     <PreferenceCategory  
  23.         android:key="location_category"  
  24.         android:layout="@layout/category_null"  
  25.         android:title="@null" >  
  26.     </PreferenceCategory>  
  27.       
  28.     <CheckBoxPreference   
  29.         android:key="keep_screen_on"   
  30.          android:layout="@layout/schpwr_background_double_top"  
  31.         android:widgetLayout="@layout/accelerometer_checkbox"  
  32.         android:title="@string/keep_screen_on"   
  33.         android:summary="@string/keep_screen_on_summary"/>  
  34.   
  35.     <CheckBoxPreference   
  36.         android:key="allow_mock_location"   
  37.           android:layout="@layout/schpwr_background_double_bottom"  
  38.         android:widgetLayout="@layout/accelerometer_checkbox"  
  39.         android:title="@string/allow_mock_location"   
  40.         android:summary="@string/allow_mock_location_summary"/>  
  41.   
  42.     <PreferenceCategory  
  43.         android:key="location_category"  
  44.         android:layout="@layout/category_null"  
  45.         android:title="@null" >  
  46.     </PreferenceCategory>  
  47.       
  48.     <ListPreference  
  49.         android:layout="@layout/schpwr_background_double_top"  
  50.         android:widgetLayout="@layout/pref_widget_more"  
  51.         android:key="hdcp_checking"  
  52.         android:title="@string/hdcp_checking_title"  
  53.         android:dialogTitle="@string/hdcp_checking_dialog_title"  
  54.         android:entries="@array/hdcp_checking_titles"  
  55.         android:entryValues="@array/hdcp_checking_values" />  
  56.   
  57.     <PreferenceScreen  
  58.             android:key="local_backup_password"  
  59.              android:layout="@layout/schpwr_background_double_bottom"  
  60.             android:widgetLayout="@layout/pref_widget_more"  
  61.             android:title="@string/local_backup_password_title"  
  62.             android:summary="@string/local_backup_password_summary_none"  
  63.             android:persistent="false" >  
  64.         <intent  
  65.                 android:action="android.settings.privacy.SET_FULL_BACKUP_PASSWORD"  
  66.                 android:targetPackage="com.android.settings"  
  67.                 android:targetClass="com.android.settings.SetFullBackupPassword" />  
  68.     </PreferenceScreen>  
  69.   
  70.     <PreferenceCategory android:key="debug_ui_category"  
  71.         android:layout="@layout/category_normal"  
  72.             android:title="@string/debug_ui_category">  
  73.   
  74.         <CheckBoxPreference  
  75.             android:key="strict_mode"  
  76.             android:layout="@layout/schpwr_background_double_top"  
  77.             android:widgetLayout="@layout/accelerometer_checkbox"  
  78.             android:title="@string/strict_mode"  
  79.             android:summary="@string/strict_mode_summary"/>  
<CheckBoxPreference android:key="enable_adb" android:layout="@layout/static_background"android:widgetLayout="@layout/accelerometer_checkbox"android:title="@string/enable_adb" android:summary="@string/enable_adb_summary"/><PreferenceCategoryandroid:key="location_category"android:layout="@layout/category_null"android:title="@null" ></PreferenceCategory><Preferenceandroid:key="verifier_device_identifier"android:layout="@layout/static_background"android:widgetLayout="@layout/pref_widget_more"style="?android:attr/preferenceInformationStyle"android:title="@string/verifier_device_identifier"android:summary="@string/verifier_device_identifier_not_available"android:persistent="false" /><PreferenceCategoryandroid:key="location_category"android:layout="@layout/category_null"android:title="@null" ></PreferenceCategory><CheckBoxPreference android:key="keep_screen_on" android:layout="@layout/schpwr_background_double_top"android:widgetLayout="@layout/accelerometer_checkbox"android:title="@string/keep_screen_on" android:summary="@string/keep_screen_on_summary"/><CheckBoxPreference android:key="allow_mock_location" android:layout="@layout/schpwr_background_double_bottom"android:widgetLayout="@layout/accelerometer_checkbox"android:title="@string/allow_mock_location" android:summary="@string/allow_mock_location_summary"/><PreferenceCategoryandroid:key="location_category"android:layout="@layout/category_null"android:title="@null" ></PreferenceCategory><ListPreferenceandroid:layout="@layout/schpwr_background_double_top"android:widgetLayout="@layout/pref_widget_more"android:key="hdcp_checking"android:title="@string/hdcp_checking_title"android:dialogTitle="@string/hdcp_checking_dialog_title"android:entries="@array/hdcp_checking_titles"android:entryValues="@array/hdcp_checking_values" /><PreferenceScreenandroid:key="local_backup_password"android:layout="@layout/schpwr_background_double_bottom"android:widgetLayout="@layout/pref_widget_more"android:title="@string/local_backup_password_title"android:summary="@string/local_backup_password_summary_none"android:persistent="false" ><intentandroid:action="android.settings.privacy.SET_FULL_BACKUP_PASSWORD"android:targetPackage="com.android.settings"android:targetClass="com.android.settings.SetFullBackupPassword" /></PreferenceScreen><PreferenceCategory android:key="debug_ui_category"android:layout="@layout/category_normal"android:title="@string/debug_ui_category"><CheckBoxPreferenceandroid:key="strict_mode"android:layout="@layout/schpwr_background_double_top"android:widgetLayout="@layout/accelerometer_checkbox"android:title="@string/strict_mode"android:summary="@string/strict_mode_summary"/>

R/layout/static_background.xml

[html] view plain copy print ?
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:layout_width="match_parent"  
  3.     android:layout_height="wrap_content"  
  4.     android:background="@drawable/roundcornerfull"  
  5.     android:gravity="center_vertical"  
  6.     android:orientation="horizontal"  
  7.     android:maxHeight="40dp">  
  8.   
  9.     <RelativeLayout  
  10.         android:layout_width="wrap_content"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_marginBottom="6.0dip"  
  13.         android:layout_marginLeft="15.0dip"  
  14.         android:layout_marginRight="6.0dip"  
  15.         android:layout_marginTop="6.0dip"  
  16.         android:layout_weight="1.0" >  
  17.     <LinearLayout  
  18.         android:orientation="vertical"  
  19.         android:layout_width="wrap_content"  
  20.         android:layout_height="wrap_content">  
  21.         <TextView  
  22.             android:id="@android:id/title"  
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:ellipsize="marquee"  
  26.             android:fadingEdge="horizontal"  
  27.             android:singleLine="true"  
  28.             android:textColor="#ff000000"  
  29.             android:textSize="18.0sp" />  
  30.         <TextView  
  31.             android:id="@android:id/summary"  
  32.             android:layout_width="wrap_content"  
  33.             android:layout_height="wrap_content"  
  34.             android:ellipsize="marquee"  
  35.             android:fadingEdge="horizontal"  
  36.             android:singleLine="true"  
  37.             android:textColor="#ff000000"  
  38.             android:textSize="12.0sp" />  
  39.     </LinearLayout>  
  40.           
  41.     </RelativeLayout>  
  42.   
  43.     <LinearLayout  
  44.         android:id="@android:id/widget_frame"  
  45.         android:layout_width="wrap_content"  
  46.         android:layout_height="fill_parent"  
  47.         android:gravity="center_vertical"  
  48.         android:orientation="vertical" />  
  49.   
  50. </LinearLayout>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/roundcornerfull"android:gravity="center_vertical"android:orientation="horizontal"android:maxHeight="40dp"><RelativeLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="6.0dip"android:layout_marginLeft="15.0dip"android:layout_marginRight="6.0dip"android:layout_marginTop="6.0dip"android:layout_weight="1.0" ><LinearLayoutandroid:orientation="vertical"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextViewandroid:id="@android:id/title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:ellipsize="marquee"android:fadingEdge="horizontal"android:singleLine="true"android:textColor="#ff000000"android:textSize="18.0sp" /><TextViewandroid:id="@android:id/summary"android:layout_width="wrap_content"android:layout_height="wrap_content"android:ellipsize="marquee"android:fadingEdge="horizontal"android:singleLine="true"android:textColor="#ff000000"android:textSize="12.0sp" /></LinearLayout></RelativeLayout><LinearLayoutandroid:id="@android:id/widget_frame"android:layout_width="wrap_content"android:layout_height="fill_parent"android:gravity="center_vertical"android:orientation="vertical" /></LinearLayout>
R/layout/accelerometer_checkbox.xml

[html] view plain copy print ?
  1. <CheckBox xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     android:id="@android:id/checkbox"  
  3.     android:layout_width="80dp"  
  4.     android:layout_height="wrap_content"  
  5.     android:layout_gravity="center_vertical"  
  6.     android:layout_marginRight="4.0dip"  
  7.     android:button="@drawable/schpwr_alarm_clock_background"  
  8.     android:clickable="false"  
  9.     android:focusable="false"/>  
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/checkbox"android:layout_width="80dp"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_marginRight="4.0dip"android:button="@drawable/schpwr_alarm_clock_background"android:clickable="false"android:focusable="false"/>

R/drawable/schpwr_alarm_clock_background.xml

[html] view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <item android:state_checked="true" android:drawable="@drawable/auto_on_blue"/>  
  4.     <item android:state_checked="false" android:drawable="@drawable/auto_off"/>  
  5.     <item android:drawable="@drawable/auto_off"/>  
  6. </selector>  
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="true" android:drawable="@drawable/auto_on_blue"/><item android:state_checked="false" android:drawable="@drawable/auto_off"/><item android:drawable="@drawable/auto_off"/>
</selector>

R/layout/pref_widget_more.xml

[html] view plain copy print ?
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <ImageView xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="wrap_content"  
  4.     android:layout_height="wrap_content"  
  5.     android:layout_alignParentRight="true"  
  6.     android:layout_marginRight="22.0dip"  
  7.     android:layout_gravity="center_vertical"  
  8.     android:src="@drawable/arrow_select" />  
<?xml version="1.0" encoding="UTF-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_marginRight="22.0dip"android:layout_gravity="center_vertical"android:src="@drawable/arrow_select" />

R/drawable/arrow_select.xml

[html] view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <selector  
  3.   xmlns:android="http://schemas.android.com/apk/res/android">  
  4.     <item android:state_focused="true" android:drawable="@drawable/listarrowblue" />  
  5.     <item android:state_pressed="true" android:drawable="@drawable/listarrowblue" />  
  6.     <item android:drawable="@drawable/listarrow" />  
  7. </selector>  
<?xml version="1.0" encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android"><item android:state_focused="true" android:drawable="@drawable/listarrowblue" /><item android:state_pressed="true" android:drawable="@drawable/listarrowblue" /><item android:drawable="@drawable/listarrow" />
</selector>

其他以此类推


http://chatgpt.dhexx.cn/article/LPWM2Ls0.shtml

相关文章

数据存储: CheckBoxPreference

最近&#xff0c;做一个项目&#xff0c;使用 Preference 非常频繁&#xff0c;之前就很想写一些关于 android 数据存储的文章&#xff0c;这次机会来了。 先从小出着手吧&#xff0c;CheckBoxPreference 小巧可爱&#xff0c;使用简单。但是使用的时候&#xff0c;还是需要注意…

CheckBoxPreference组件

CheckBoxPreference 选中为true 取消选中为false 它的值会以boolean的形式储存在SharedPreferences中。 <?xml version"1.0" encoding"utf-8"?><PreferenceScreenxmlns:android"http://schemas.android.com/apk/res/android"><…

Android 自定义CheckBoxPreference的CheckBox复选框

在使用Android的Preference&#xff0c;有时为了让我们的界面更加美观&#xff0c;我们会自定义自己的Preference。今天就主要说一下怎样自定义CheckBoxPreference的CheckBox按钮。 系统默认CheckBoxPreference的CheckBox样式 自定义后的CheckBox样式 其实&#xff0c;关键的一…

最好用的手机端C/C++语言编程软件, 不要说没电脑就不学编程了!

今天介绍一个软件—C编译器(c4droid)&#xff0c;可以直接编辑运行C/C程序&#xff0c;代码高亮、语法检查&#xff0c;使用起来非常不错&#xff0c;下面我简单介绍一下这个软件的安装和使用&#xff1a; 安装C编译器&#xff0c;这个直接在手机应用中搜索就行&#xff0c;如…

最新版手机端C/C++语言编程的软件

今天介绍一个软件—C编译器(c4droid)&#xff0c;可以直接编辑运行C/C程序&#xff0c;代码高亮、语法检查&#xff0c;使用起来非常不错&#xff0c;下面我简单介绍一下这个软件的安装和使用&#xff1a; 安装C编译器&#xff0c;这个直接在手机应用中搜索就行&#xff0c;如…

C语言编程工具软件推荐

c语言编程软件适于编写系统软件&#xff0c;是学习编程的同学们的必备软件。c语言一种非常强大的计算机语言&#xff0c;应用非常广泛&#xff0c;不仅仅是在软件开发上&#xff0c;而且各类科研都会用到c语言。今天小编给大家汇总下C语言的编程工具 中国有句古话叫做“工欲善其…

c语言编程软件有哪些 Win7下用哪种C语言编译器

C语言是一门历史很长的编程语言&#xff0c;其编译器和开发工具也多种多样&#xff0c;其开发工具包括编译器&#xff0c;现举几个开发工具供大家选择&#xff0c;当然也要根据自己的操作系统来选择适合自己的开发工具 好多刚开始接触c语言的朋友都想知道用上面软件开发c语言…

手机上可以编程看代码的软件

以后大家会在路上看到很多人拿着手机,他不是在聊天,他有可能是运维工程师、也可能是算法开发、也可能是java开发,还可能是客户端开发,也可能是前端开发... 让你编程一直在路上,这到底是程序员的福音,还是码农的枷锁。 粉丝提问: 这里介绍几款可以在手机上编程的app,分…

学习c语言编程用什么软件_用C编程

学习c语言编程用什么软件 We would start writing basic programs in C now. You need to have required software installed and configured in your system. Refer to the article of Hello World and ensure that you are able to compile and run the program. 我们现在就开…

怎样查看C语言的程序内容,什么手机软件能看c语言文件?

C语言编译器和C编译器这2个手机软件就可以&#xff0c;而且还可以直接运行C语言程序&#xff0c;使用起来非常方便&#xff0c;下面我简单介绍一下这2个软件的安装和使用&#xff0c;感兴趣的朋友可以在自己手机上尝试一下&#xff1a; C语言编译器 这是手机上一个纯粹的C语言编…

c语言编程开发app,C语言编程app

C语言编程是一款掌上C语言学习软件&#xff0c;平台为用户提供专业的C语言学习资源&#xff0c;用户可以随时在线进行刷题学习&#xff0c;还能将错题记录和题目收藏&#xff0c;方便用户进行针对训练&#xff0c;轻松备考计算机二级&#xff0c;有需要的朋友快来下载吧&#x…

C语言编译器(C语言编程软件)

桌面操作系统 对于当前主流桌面操作系统而言&#xff0c;可使用 Visual C、GCC 以及 LLVM Clang 这三大编译器。 Visual C&#xff08;简称 MSVC&#xff09;是由微软开发的&#xff0c;只能用于 Windows 操作系统&#xff1b;GCC 和 LLVM Clang 除了可用于 Windows 操作系统…

c语言程序设计网站有哪些,C语言编程软件有哪些?

C语言是一门通用计算机编程语言&#xff0c;应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。 尽管C语言提供了许多低级处理的功能&#xff0c;但仍然保持着良好跨平台的特性&#xf…

最火的C语言编程软件,适合编写C语言代码的编程软件有哪些

C语言基本上是大学计算机及其相关专业在大一上学期就会开的一门课程,但是很多学生就是在大一上学期期末的时候很着急,因为自己完全没有学好C语言,感觉一学期白学了,其实究其主要原因,还是因为你在上课认真听了,也做了课堂作业,但是却没有在课后好好的自己去主动敲代码,…

常用的C语言编程工具

中国有句古话叫做“工欲善其事&#xff0c;必先利其器”&#xff0c;可见我们对工具的利用是从祖辈就传下来的&#xff0c;而且也告诉我们在开始做事之前先要把工具准备好。有了好的工具那么我们做起事来也会事半功倍。学习C语言也是一样的&#xff0c;对于初学者来说往往选择一…

手机上做c语言作业的软件下载,c语言编程软件手机版下载-C语言编程 安卓版v1.0.2-PC6安卓网...

C语言编程这是为众多考证用户专门制作的在线学习软件&#xff0c;C语言编程app将考证要用到的相关知识归纳好经过题库的形式来让大家熟练和上手&#xff0c;C语言编程app可以协助大家经过二级计算机考试。 软件介绍 C语言编程是一款掌上C语言学习软件&#xff0c;平台为用户提供…

C语言学习——编程软件安装和使用

C语言学习——软件安装和使用 C语言编程软件适于编写系统软件&#xff0c;是学习编程的同学们的必备软件。今天小编给大家推荐一下自己用的C语言编程软件。 一、Microsoft Visual C 2010 Express &#xff08;国家计算机等级专用&#xff09; 链接:https://pan.baidu.com/s/…

C/C++编程工具及实用小软件推荐

目录 1、概述 2、IDE开发工具介绍 2.1、Visual Studio 2.2、QT Creator 3、代码查看与编辑工具 3.1、Visual Studio Code 3.2、Source Insight 4、实用小软件工具推荐 4.1、Notepad 4.2、Everything 5、最后 经常有C/C初学者会问&#xff0c;有哪些常用的IDE开发编程…

c语言程序设计是系统软件吗,学习c语言和编程c语言的电脑软件和手机软件有哪些?...

C语言作为一门起源比较早的编程语言&#xff0c;可以编程的手机软件和电脑软件非常多&#xff0c;下面我简单介绍几个&#xff0c;感兴趣的朋友可以自己尝试一下&#xff1a; 手机软件 1.C语言编译器&#xff1a;这是手机上的一个C语言编程软件&#xff0c;可以直接在手机上编译…

C/C++ 用什么软件编程

一款方便顺手的编程软件对于 C/C 开发者们来说&#xff0c;无疑会节省非常多不必要的环境安装和学习使用教程的时间。看到一些回答围绕不同操作系统&#xff0c;推荐了不同的IDE。我在这里给大家介绍一个全平台都通用、轻量且功能强大的在线编辑器 Lightly。它是首个根据中国开…