Wednesday 21 July 2021

How to set filter property in ImageView Android studio

I have a yellow sparkline png and I would like to change the filter by adding some css. Colors will change according to positive or negative number.

So, if the number is negative, the line should be:

CSS

filter: hue-rotate(300deg) saturate(210%) brightness(0.7) contrast(170%);

If positive:

filter: hue-rotate(85deg) saturate(80%) brightness(0.85);

ImageView:

       <ImageView
                android:layout_width="match_parent"
                android:layout_height="36dp"
                android:id="@+id/sparkline"
                android:layout_toRightOf="@+id/coin_icon"
                android:src="@drawable/line_24"
                android:layout_marginRight="5dp"
                />

MainActivity.Java

ImageView sparkline;

sparkline = itemView.findViewById(R.id.sparkline);

if(datum.getQuote().getUSD().getPercentChange24h() < 0.000){
  ///red
}else{
    //green

 }

EDIT:

What I have:

enter image description here

What I want:

enter image description here

EDIT:

Now I used an ImageFilterView:

 <androidx.constraintlayout.utils.widget.ImageFilterView
                android:layout_width="80dp"
                android:layout_height="50dp"
                android:id="@+id/sparkline"
                android:layout_marginRight="2dp"
                app:saturation="80"
                app:brightness="0.85"
                android:src="@drawable/btc_spike" />

But I still need to add the hue-rotate(300deg) I couldn't find anything yet to change the color.



from How to set filter property in ImageView Android studio

No comments:

Post a Comment