0

hi i have problem with set tint color .. i want when choose color from color int Changes the color of the imageview with the same color i selected So when i click on color the imageview dont change the tint


Noticeable: imageview use Drawable with default white color

Noticeable: i don't want change Drawable color because it well use for many image view with different colors

Noticeable:Toast work perfectly fine.

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 code

   <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 array File

 <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>
  • Possible duplicate of [How to set tint for an image view programmatically in android?](https://stackoverflow.com/questions/20121938/how-to-set-tint-for-an-image-view-programmatically-in-android) – Reaz Murshed Apr 19 '19 at 21:33

0 Answers0