public class DisabledAppearanceCheckboxPreference extends CheckBoxPreference {
protected boolean mEnabledAppearance = false;
public DisabledAppearanceCheckboxPreference(Context context,
AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
boolean viewEnabled = isEnabled()&&mEnabledAppearance;
enableView(view, viewEnabled);
}
protected void enableView( View view, boolean enabled){
view.setEnabled(enabled);
if ( view instanceof ViewGroup){
ViewGroup grp = (ViewGroup)view;
for ( int index = 0; index < grp.getChildCount(); index++)
enableView(grp.getChildAt(index), enabled);
}
}
public void setEnabledAppearance( boolean enabled){
mEnabledAppearance = enabled;
notifyChanged();
}
@Override
protected void onClick() {
if ( mEnabledAppearance)
super.onClick();
else{
//展示其他东西 }
}
}
继承CheckBoxPreference
最新推荐文章于 2022-06-13 10:27:49 发布
本文介绍了一个公共类,用于在特定情况下自定义复选框的禁用外观,包括视图启用状态的调整、点击事件的特殊处理。
1万+

被折叠的 条评论
为什么被折叠?



