Search code examples
androidxmlandroid-imagebutton

Fill the transparent part of the drawable with a specific color


I have this transparent image that I want to fill a specific color inside of the transparent part.

image

I have been able to fill up this image a specific color I want, but the problem is that the color is also filling up the outside part of the ImageButton.

Here is the sample:

image

How can I remove the excess red color outside of the drawable?

Here is my current xml:

<ImageButton
    android:id="@+id/button_scan"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginRight="4dp"
    android:layout_weight="0.25"
    android:src="@drawable/ic_scan"
    android:background="@color/aub_red"
    android:backgroundTintMode="screen"
    android:textColor="@color/edittext_text" />

Solution

  • try to build by adding theses

    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    

    if your image ratio affected by above change you can use

    android:scaleType="fitCenter"