嗨,我在设置色调颜色时遇到了问题。我想从 color int 中选择颜色时,用 imageview 更改颜色。 我选择了相同的颜色,所以当我单击颜色时,imageview不会更改色调
值得注意:imageview使用默认默认为白色的Drawable
值得注意的是:我不想更改Drawable颜色,因为它很好地用于许多具有不同颜色的图像视图
值得注意的是:吐司做得很好。
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog_lib, container, false);
SpectrumPalette spectrumPalette = (SpectrumPalette) v.findViewById(R.id.palettelib);
spectrumPalette.setOnColorSelectedListener(this);
ImageView img = (ImageView) v.findViewById(R.id.viewr);
return v;
}
@Override
public void onColorSelected(@ColorInt int color) {
Toast.makeText(getContext(), "Color selected: #" + Integer.toHexString(color).toUpperCase(), Toast.LENGTH_SHORT).show();
if(color==0){
ImageViewCompat.setImageTintList(img, ColorStateList.valueOf(color));
}if(color==1){
ImageViewCompat.setImageTintList(img, ColorStateList.valueOf(color));
}if(color==2){
ImageViewCompat.setImageTintList(img, ColorStateList.valueOf(color));
}if(color==3){
ImageViewCompat.setImageTintList(img, ColorStateList.valueOf(color));
}if(color==4){
ImageViewCompat.setImageTintList(img, ColorStateList.valueOf(color));
}
}
Xml代码
<com.thebluealliance.spectrum.SpectrumPalette
android:id="@+id/palettelib"
app:spectrum_autoPadding="true"
app:spectrum_colors="@array/demo_colors"
app:spectrum_columnCount="12"
app:spectrum_outlineWidth="2dp" />
颜色阵列文件
<color name="white">#FFFFFF</color>
<color name="orange">#FF8B00</color>
<color name="deep_purple">#5A1ACC</color>
<color name="light_blue">#03A9F4</color>
<color name="green">#4CAF50</color>
<color name="deep_yellow">#F7FF00</color>
<color name="blue_grey">#072DEE</color>
<color name="pink">#E91E63</color>
<color name="brown">#795548</color>
<color name="purple">#9C27B0</color>
<color name="deep_red">#C50C0C</color>
<color name="teal">#00887D</color>
<array name="demo_colors">
<item>@color/white</item>
<item>@color/deep_red</item>
<item>@color/orange</item>
<item>@color/deep_yellow</item>
<item>@color/brown</item>
<item>@color/purple</item>
<item>@color/pink</item>
<item>@color/deep_purple</item>
<item>@color/light_blue</item>
<item>@color/blue_grey</item>
<item>@color/green</item>
<item>@color/teal</item>