我正试图在这里使用这个库,但我发现有些困难,请帮我一把 - https://materialdoc.com/components/pickers/#color-picker。它给了我这个错误,我似乎找不到办法: - 必需:com.android.colorpicker.ColorPickerPalett - 到目前为止我有这个:当我尝试给视图充气时,我收到了错误。
int[] color_array = this.getResources().
getIntArray(R.array.default_color_choice_values);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
colorPickerDialog.initialize(
R.string.color_picker_default_title, color_array, 0, 2, color_array.length);
colorPickerDialog.show(getFragmentManager(), "cal");
LayoutInflater layoutInflater = LayoutInflater.from(this);
ColorPickerPalette colorPickerPalette = layoutInflater.inflate(R.layout.custom_picker, null);
ColorPickerSwatch.OnColorSelectedListener mOnColorSelectedListener = new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
Log.v(LOG_TAG, "Will fill the code later on");
}
};
colorPickerPalette.init(color_array.length, 3, mOnColorSelectedListener);
colorPickerPalette.drawPalette(color_array, 0);
}
答案 0 :(得分:1)
如果xml(custom_picker)上的根标签正好是layoutInflater.inflate(R.layout.custom_picker, null);
<com.android.colorpicker.ColorPickerPalette ....
的结果将只是ColorPallet类型
否则,如果你有LinearLayout或任何其他ViewGroup,你必须更改你的代码以找到内部视图(假设你有一个选择器的标签@ + id)
ViewGroup resultLayout = layoutInflater.inflate(R.layout.custom_picker, null);
ColorPickerPalette colorPickerPalette = resultLayout.findViewById(R.id.color_picker_id_at_xml);