1

私は PreferenceScreen に多くの CheckBox を含め、テーマを次のように参照しています。

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

CheckBox の間の仕切りをカスタマイズしたいのですが、次のように PreferenceScreen のカスタム レイアウトを作成することもできません。

<?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 でビューを作成しようとしましたが、次のように機能しません:

  <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 にも次のように記載されています。

  <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);
    }
}

どんな助けでも大歓迎です、ありがとう

4

2 に答える 2

3

これを試して:

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

xml から設定をロードするための呼び出しの後に実行します (おそらく の最後にonCreate())。

于 2013-07-28T03:42:51.757 に答える