如何设置‘Currently playing’投屏界面文字颜色及弹窗专属主题?
Absolutely—you can absolutely apply a standalone theme just for that "Currently playing" cast dialog without breaking your app's existing styles. Here's how to solve the white-on-white text issue step by step:
Step 1: Create a Custom Dialog Theme
First, define a dedicated theme for the cast dialog in your res/values/styles.xml. Inherit from a base media router dialog theme (either AppCompat or platform-specific) and override the text/background colors to ensure proper contrast:
<style name="CustomCastDialogTheme" parent="@style/Theme.AppCompat.Dialog.Alert"> <!-- Set text to a color that contrasts with your white background --> <item name="android:textColorPrimary">#000000</item> <!-- Keep your existing white background (matches your app's needs) --> <item name="android:windowBackground">#FFFFFF</item> <!-- If you prefer using the platform's native media router theme, use this parent instead: parent="@android:style/Theme.DeviceDefault.Dialog.MediaRouter" --> </style>
Step 2: Apply the Theme to the Cast Dialog
You have two easy options to hook this theme up:
Option 1: Use a Custom Dialog Factory (Granular Control)
If you're using a MediaRouteButton in your layout, override the dialog it generates to use your custom theme:
MediaRouteButton castButton = findViewById(R.id.your_cast_button_id); castButton.setDialogFactory(new MediaRouteDialogFactory() { @Override public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) { // Return the dialog with your custom theme applied return new MediaRouteControllerDialog(context, R.style.CustomCastDialogTheme); } });
Option 2: Set the Theme Globally (Simpler)
To apply this theme to all cast dialogs in your app, add one line to your main app theme in styles.xml:
<style name="YourAppMainTheme" parent="Theme.AppCompat.Light"> <!-- Your existing theme properties (keep textColor/colorPrimary as white) --> <item name="mediaRouteTheme">@style/CustomCastDialogTheme</item> </style>
This approach ensures your main app's styles remain intact (white text/background where you need it) while the cast dialog gets its own contrasting styles to make the "Currently playing" text visible.
内容的提问来源于stack exchange,提问作者Hrk

