我有 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>
也不工作,
更新:
我的布局.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>
首选项.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);
}
}
任何帮助将不胜感激,谢谢