Android 为CheckBoxPreference Preference 控件添加样式

来源:互联网 发布:fluent16.0软件下载 编辑:程序博客网 时间:2024/06/06 21:39

<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"/>    <PreferenceCategory        android:key="location_category"        android:layout="@layout/category_null"        android:title="@null" >    </PreferenceCategory>        <Preference        android: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" />    <PreferenceCategory        android: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"/>    <PreferenceCategory        android:key="location_category"        android:layout="@layout/category_null"        android:title="@null" >    </PreferenceCategory>        <ListPreference        android: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" />    <PreferenceScreen            android: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" >        <intent                android: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">        <CheckBoxPreference            android: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

<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">    <RelativeLayout        android: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"><TextView    android: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" /><TextView    android: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>    <LinearLayout        android: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

<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

<?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

<?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

<?xml version="1.0" encoding="utf-8"?><selector  xmlns: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>

其他以此类推

原创粉丝点击