Search code examples
androidcolorsimageviewtransparencyandroid-appwidget

Android App Widget: how to change color AND transparency of ImageView


Hi and thank for your help:

I have an App Widget with a ImageVivew.

The ImageView is simply a rounded rectangle.

I need to change the color AND transparency of it at runtime.

Please how do I achieve this?

This is the Drawable I am currently using as the ImageView src:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
 android:shape="rectangle"> 
  <solid
    android:color="@android:color/white" />
<corners 
    android:radius="20dp" 
    /> 
</shape> 

If I use:

updateViews.setInt(R.id.backgroundimage, "setColorFilter",backcolr );

where "backcolr" is a transparent color, the color changes, but the ImageView remains totally opaque.

Any help appreciated!


Solution

  • I did it!

    updateViews.setInt(R.id.backgroundimage,"setColorFilter",backcolr );
    updateViews.setInt(R.id.backgroundimage,"setAlpha",Color.alpha(backcolr) );