当对话框关闭时,即选择完颜色后,我们就要马上回去更新文本的颜色和将颜色值保存到键值里面,代码如下:
@Override protected void onDialogClosed(boolean positiveResult) { if (positiveResult) { mCurrentColor = mCPView.getColor(); summary.setTextColor(mCurrentColor); SharedPreferences.Editor editor = getEditor(); editor.putInt(getKey(), mCurrentColor); editor.commit(); callChangeListener(new Integer(mCurrentColor)); } }
通过重写,onDialogClosed 回调函数,到这一步整个的封装就己结束,在XML可以通过如下使用
<com.terry.util.ColorPickerPreference android:key="colorpiker" android:persistent="true" android:summary="@string/app_name" android:dialogTitle="@string/str_fontscolor" android:title="@string/str_fontscolor" />