【发布时间】:2020-02-11 10:05:08
【问题描述】:
我有一个 PreferenceFragemnt,我想对 Preferences 产生一个服装连锁反应。所以我开始制作 CostumPreference 但我不知道如何设置背景可绘制对象。我找到了this post。但这对我不起作用。
这是我的服装偏好:
public class RipPreference extends Preference {
private Context ctx;
public RipPreference(Context context, AttributeSet attrs) {
super(context, attrs);
ctx = context;
}
public RipPreference(Context context) {
super(context);
ctx = context;
}
//This event won't be tiggered
protected View onCreateView(ViewGroup parent) {
//Preference is not an View so there is no onCreateView
View view = super.onCreateView(parent);
view.setBackground(<my ripple>);
return view;
}
}
private void setCustomStyle(View view) {
RippleDrawable drawable = (RippleDrawable) ctx.getDrawable(R.drawable.settings_preference_background);
view.setBackground(drawable);
}
}
也许有人有其他想法。 :)
【问题讨论】:
标签: android android-preferences