我创建了一个自定义首选项来设置一个可绘制的背景9补丁。我点击首选项时使用OnPreferenceClickListener打开弹出窗口。从Preference更改为CustomPreference后,单击侦听器将停止工作。
代码:
public class CustomPreference extends Preference {
public CustomPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public View getView(View convertView, ViewGroup parent) {
View view = super.getView(convertView, parent);
view.setBackgroundResource(R.drawable.ic_settings_patch);
return view;
}
}
点击听众:
CustomPreference preference = (CustomPreference) findPreference("custom_preference");
preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
return true;
}
});
XML:
<com.example.CustomPreference
android:key="custom_preference"
android:summary="Summary"
android:title="Title" />