3
我的自定义首选项类有助于颜色选择。
自定义首选项调用GridView Intent,它包含9种颜色。
但是我的自定义类不能刷新颜色,这在GridView的
用户选择当我完成偏好的意图,然后重新启动偏好,
颜色显示出来我,因为我选择的。Android自定义首选项改变覆盖
onBindView()
方法,我过度。这是完美的。
但我不知道我必须重写刷新颜色的方法。
public class ConfigImage extends Preference
{
Context mContext;
public ConfigImage(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
this.mContext = context;
}
public ConfigImage(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
this.mContext = context;
setLayoutResource(R.layout.preference_image);
}
@Override
public void onBindView(View view)
{
super.onBindView(view);
ImageView imageView = (ImageView) view.findViewById(R.id.preference_image_iv_color);
if (imageView != null)
{
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
int colorIndex = sharedPref.getInt("setting_color_default", 3);
imageView.setBackgroundColor(Color.parseColor(ColorStorage.colors[colorIndex]));
}
}
}
<PreferenceCategory
android:key="setting_color_info"
android:title="색상" >
<com.pack.ConfigImage
android:id="@+id/setting_color_default"
android:key="setting_color_default"
android:selectable="true"
android:summary="Choose default color"
android:title="Default Color"
settings:background="#FFFFFFFF" />
</PreferenceCategory>