Android 为CheckBoxPreference Preference 控件添加样式

来源:互联网 发布:淘宝小额红包 编辑:程序博客网 时间:2024/05/29 13:34

楼主最近在Mms的新功能以及布局,找了好久的好东西,在此分享,原文链接:http://blog.csdn.net/chenshijun0101/article/details/8191429

[html] view plaincopy
  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"/>  

R/layout/static_background.xml

[html] view plaincopy
  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>  
R/layout/accelerometer_checkbox.xml

[html] view plaincopy
  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"/>  

R/drawable/schpwr_alarm_clock_background.xml

[html] view plaincopy
  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>  

R/layout/pref_widget_more.xml

[html] view plaincopy
  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" />  

R/drawable/arrow_select.xml

[html] view plaincopy
  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>  

其他以此类推
0 0
原创粉丝点击