How can I style the title of a MediaRouter dialog?

1.6k views Asked by At

I'm using mediarouter-v7 v23.1.1 to show a chromecast / media router chooser dialog. Now I try to style this thing - while I could change the background color and list item text style with this:

<style name="Theme.MediaRouter.Light">
    <item name="android:background">@color/orange</item>
    <item name="mediaRouteChooserPrimaryTextStyle">@style/my_custom_style</item>
</style>

I was not able to override the style of the dialog's title. This and other attempts were not successful:

<style name="Theme.MediaRouter.Light">
    <item name="android:windowTitleStyle">@style/my_title_style</item>
</style>
<style name="my_item_style">
    <item name="android:textColor">@color/blue</item>
</style>

As I understood it, a dialog has its own window, therefore android:windowTitleStyle of the (dialog) theme that I override in my custom styles should be applied, but its not. I also looked into the implementation of the mediarouter dialog to see if they do anything fancy (like hiding the window and adding a custom element as their title), but they do not, they simply call setTitle(...) on the Dialog instance.

What am I doing wrong?

1

There are 1 answers

3
geniushkg On BEST ANSWER

Unfortunately that dialog doesn't follow the standard theme (Dialogs in Android are all pretty unfriendly in general but that one is among the hardest to work with). Since that dialog is provided by media router, you can only provide a customized theme if you replace that completely with your own dialog.

You can try subclassing MediaRouteDialogFactory and override onCreateChooserDialogFragment() method and pass your implementation to the ActionProvide:

mediaRouteActionProvider.setDialogFactory(yourDialogFactoryImlementation)

You can take a look at the CCL where I do a similar thing not for the chooser dialog but for the controller