如何自定义的CheckBox preference之间分隔在preferenceScreen [英] How to customize divider between CheckBoxPreference in PreferenceScreen

查看:556
本文介绍了如何自定义的CheckBox preference之间分隔在preferenceScreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有preferenceScreen包含许多CheckBox和所指向以主题为:

I have PreferenceScreen contain many CheckBox and refered to theme as:

  <activity 
        android:name=".Prefs" 
        android:label="@string/app_name" 
        android:theme="@style/PreferencesTheme">

我想将CheckBox之间定制分频器,但我也不能即时为波纹管创建为preferenceScreen自定义布局:

i want to customize divider between the CheckBox , but i cant also im create custom layout for the PreferenceScreen as bellow :

<?xml version="1.0" encoding="utf-8" ?> 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

 <CheckBoxPreference 
    android:summary="checkbox one" 
    android:key="splash" 
    android:layout="@layout/mylayout"      
     /> 
 <CheckBoxPreference 
    android:summary="checkbox two"
    android:key="splash_music" 
    android:layout="@layout/mylayout"      
     /> 
</PreferenceScreen>

我尝试创建视图mylayout.xml,但它不是作为工作:

i try to create view in mylayout.xml but it doesn't work as :

  <View 
  android:id="@+id/divider" 
  android:background="@drawable/divider" 
  android:layout_width="match_parent" 
  android:layout_height="5dp" 
  android:layout_below="@+android:id/title" /> 

也prefs_style.xml为:

also in prefs_style.xml as:

  <item name="android:divider">@color/red_color</item>

也没有工作,

更新:

mylayout.xml

<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">
<LinearLayout 
  android:layout_width="wrap_content" 
  android:layout_height="match_parent" 
  android:gravity="center" 
  android:minWidth="@dimen/preference_icon_minWidth" 
  android:orientation="horizontal">
<ImageView 
  android:id="@+android:id/icon" 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_gravity="center" 
  android:minWidth="48dp" /> 
</LinearLayout>
<RelativeLayout 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:layout_marginLeft="16dip" 
  android:layout_marginRight="8dip" 
  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:textAppearance="?android:attr/textAppearanceMedium" 
  android:fadingEdge="horizontal" /> 
<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:textColor="?android:attr/textColorSecondary" 
  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:minWidth="@dimen/preference_widget_width" 
  android:gravity="center" 
  android:orientation="vertical" /> 
</LinearLayout>

prefs_style.xml

<?xml version="1.0" encoding="utf-8" ?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android">
 <style name="CustomWindowTitleBackground" /> 
 <style name="PreferencesTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dp</item> 
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground
</item> 
<item name="android:background">#FFDAB9</item> 
<item name="android:textColorSecondary">@color/red_color</item> 
<item name="android:textSize">25sp</item> 
<item name="android:divider">@color/red_color</item> 
</style>
</resources>

prefs.java

  public class Prefs extends PreferenceActivity{

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    Boolean customTitleSupported =  
            requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    if (customTitleSupported) { 

         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
         TextView tv = (TextView) findViewById(R.id.title_tv1); 
         tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
         tv.setText("Preference");  
         }
    addPreferencesFromResource(R.xml.prefs); 
    ListView lv = getListView();
    lv.setDivider(new ColorDrawable(Color.RED)); 
    lv.setDividerHeight(10);
    }
}

任何帮助将AP preciated,谢谢

any help will be appreciated, thanks

推荐答案

试试这个:

ListView list = (ListView) findViewbyId(android.R.id.list);
list.setDivider(new ColorDrawable(Color.RED)); // or some other color int
list.setDividerHeight((int) getResources.getDisplayMetrics().density); // or some value > 0

就做你的电话后,(在结束的onCreate()所以可能)。

这篇关于如何自定义的CheckBox preference之间分隔在preferenceScreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆