如何更改列表首选项背景?
我想要做以下
public class NewListPreferences extends ListPreference
{
public NewListPreferences(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onPrepareDialogBuilder(Builder builder) {
Dialog d = this.getDialog();
// d.getLayoutInflater();
FrameLayout f1 = (FrameLayout) d.findViewById(getDialogLayoutResource());
f1.setBackgroundResource(R.drawable.bg);
d.setContentView(f1);
super.onPrepareDialogBuilder(builder);
}
}
但我得到'空指针异常' 我也尝试了setContentView(R.id.custom_d);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" >
</ListView>
</LinearLayout>
如果我这样做
<ListPreference
android:key="units"
android:title="@string/units_setting"
android:summary="@string/units_setting_details"
android:entries="@array/units_preference"
android:entryValues="@array/units_preference_values"
android:dialogTitle="@string/units_setting_title"
android:dialogLayout="@layout/custom_d"
android:defaultValue="imperial" />
我改变了背景,但对话框不包含任何项目