having problem when set backgroundTintColor of Snackbar to a color with alpha is not 1

Viewed 98

When I show a snackbar using code below:

 Snackbar
            .make(findViewById(R.id.drawer_layout), message, Snackbar.LENGTH_SHORT)
            .setTextColor(Color.BLACK)
            .setBackgroundTint(snackbarMessageType.color)
            .show()
enum class SnackbarMessageType(val color: Int) {
    WARNING(Color.HSVToColor(80, floatArrayOf(0f,0.84f,1f))),
    NOTIFICATION(Color.HSVToColor(80, floatArrayOf(106f,0.84f,1f)))

}

A white block show under my snackbar.

enter image description here

I'm anchoring snackbar on my drawer layout.

Is it a thing comes with drawer layout, or there's just something wrong with the code?

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/background"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:itemIconTint="@color/colorPrimaryDark"
        app:itemTextAppearance="@style/TextAppearance.AppCompat.Medium"
        app:itemTextColor="?attr/colorOnBackground"
        app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
1 Answers

Seems there's some bug in the default BackgroundTintMode when it comes to background color with alpha. Found a way to overcome setting BackgroundTintMode to PorterDuff.Mode.SRC_OVER

 snackbar.setBackgroundTintMode(PorterDuff.Mode.SRC_OVER)
Related