【发布时间】:2012-04-27 18:46:33
【问题描述】:
我的自定义偏好类有助于颜色选择。
自定义首选项调用 GridView Intent 它包含 9 种颜色。
但我的自定义类无法刷新用户在 gridview 上选择的颜色
当我完成偏好意图时,然后重新启动偏好,
我选择的颜色会显示给我。
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>
【问题讨论】:
标签: android preference