Skip to content Skip to sidebar Skip to footer

Why Am I Getting Java.lang.illegalargumentexception: Background Can Not Be Translucent: #0 When Using Mediaroutebutton?

I'm trying to cast my app to Chromecast. I've started with adding a button, following the https://developers.google.com/cast/docs/android_sender_integrate guide. After I have added

Solution 1:

If you are directly instantiating the MediaRouteChooserDialog (aka. doing a bit more of a customized implementation for chromecast), and you don't want to use an AppCompat theme derivative as your app theme, you can do this:

MediaRouteChooserDialog builder = new MediaRouteChooserDialog(context, R.style.Theme_AppCompat_NoActionBar);

This passes in the default AppCompat.NoActionBar theme for the dialog to use. You can pass whatever theme you want as long as it's a descendant of AppCompat.

Works for at least in the androidx, v7-28, and v7-28 support libraries. Not sure about older versions.

Solution 2:

To anyone who runs into this (probably while upgrading an old project), don't forget to change your activity super class from Activity to AppCompatActivity.

Solution 3:

Make sure not to override the theme in your activity style parameter:

In the android manifest the application tag should have:

<application
    **android:theme="@style/Theme.AppCompat.NoActionBar"**
     android:icon="@drawable/icon"
     android:label="@string/app_name"
     android:name="MyApplication">

and in the activity tag:

<activityandroid:name=".VideoActivity"android:configChanges="orientation|screenSize"android:label="Video"android:theme="@style/Theme.AppCompat.NoActionBar" ></activity>

Solution 4:

To calculate controller color the primaryColor from your current Activity theme is used. And you have to use only fully opaque color as primaryColor to show MediaRouteButton.

Please see below the source code:

    int primaryColor = getThemeColor(context, style,
            android.support.v7.appcompat.R.attr.colorPrimary);
    if (ColorUtils.calculateContrast(COLOR_WHITE_ON_DARK_BACKGROUND, primaryColor)
            >= MIN_CONTRAST) {
        return COLOR_WHITE_ON_DARK_BACKGROUND;
    }
    return COLOR_DARK_ON_LIGHT_BACKGROUND;

Post a Comment for "Why Am I Getting Java.lang.illegalargumentexception: Background Can Not Be Translucent: #0 When Using Mediaroutebutton?"