androidandroid-drawableandroid-vectordrawableandroid-12

Why is my Android Drawable showing up with a color on top of it?


I am developing a simple, daily task reporting Android Studio app as an internal tool for the IT department I work for. I'm trying to make it as informative and easy to use as possible, adding user friendly UI. For this, I'm using AlertDialog to interact with the user, such as showing information, warnings and errors. The problem comes when I try to set an icon to the AlertDialog. It technically works but it shows a white icon, like this: Screenshot

When it is supposed to look like this: Icon

I believe Android 12 expects me to use a drawable vector, because when I use the ic_launcher_foreground drawable file it displays just fine. I just wanted to know if there's any way to override that so I can display a plain image file instead of a drawable vector. (I was wrong asuming this was the problem.) I have tried to find documentation or any posts/questions about this specific problem but I think I've been searching the wrong places.

Here's the code that builds and shows my AlertDialog (Java):

private void showGpsDialog(){
    final String dialog_title = getResources().getString(R.string.dialog_important_title);
    final String dialog_message = getResources().getString(R.string.gps_disabled_dialog_message);
    final String dialog_positive = getResources().getString(R.string.dialog_understood);
    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogRegular);
    builder.setMessage(dialog_message)
            .setPositiveButton(dialog_positive, (dialogInterface, i) -> {
            })
            .setTitle(dialog_title)
            .setIcon(R.drawable.ic_info_drawable);
    AlertDialog dialog = builder.create();
    dialog.show();
}

Here's the drawable icon xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:opacity="opaque">
    <item
        android:width="15dp"
        android:height="15dp"
        android:gravity="center"
        >
        <bitmap android:src="@drawable/info_icon"/>
    </item>
</layer-list>

Solution

  • Turns out I was making a huge, probably stupid but silent mistake. I was using a custom theme in the themes.xml file, and I had this line <item name="tint">@color/white</item> which was making all my drawables have white on top of the image it was supposed to be there, but I noticed only when I tried to display an ImageView and the same problem as my AlertDialog showed up. I just removed that line because I found out that I did not need it, and that solved the problem.