主題,這個工作對我來說:
設置自定義操作提供在菜單項
<item
android:id="@+id/media_route_menu_item"
android:title="@string/cast_menu_title"
app:actionProviderClass="MediaRouteActionProviderThemeLight"
app:showAsAction="always"/>
這是使用淺色主題
public class MediaRouteActionProviderThemeLight extends MediaRouteActionProvider {
private static final int THEME_DIALOG = android.support.v7.mediarouter.R.style.Theme_MediaRouter_Light;
/**
* Creates the action provider.
*
* @param context The context.
*/
public MediaRouteActionProviderThemeLight(Context context) {
super(context);
setDialogFactory(new MediaRouteDialogFactoryThemeLight());
}
private static class MediaRouteDialogFactoryThemeLight extends MediaRouteDialogFactory {
@NonNull
@Override
public MediaRouteChooserDialogFragment onCreateChooserDialogFragment() {
return new MediaRouteChooserDialogFragmentThemeLight();
}
@NonNull
@Override
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new MediaRouteControllerDialogFragmentThemeLight();
}
}
public static class MediaRouteChooserDialogFragmentThemeLight extends MediaRouteChooserDialogFragment {
@Override
public MediaRouteChooserDialog onCreateChooserDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteChooserDialog(context, THEME_DIALOG);
}
}
public static class MediaRouteControllerDialogFragmentThemeLight extends MediaRouteControllerDialogFragment {
@Override
public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context, THEME_DIALOG);
}
}
}
考慮與播放/暫停按鈕和音量控制對話框使用的材質顏色的主旋律,colorPrimary爲背景,textColorPrimary爲標題/字幕自定義操作提供商。如果您的應用程序使用深色主題,你應該使用下面的主題覆蓋的背景,並在類MediaRouteActionProviderThemeLight改變THEME_DIALOG常數:
<style name="CastAppThemeMediaRouter" parent="Theme.MediaRouter.Light">
<item name="colorPrimaryDark">@color/primary_dark_material_light</item>
<item name="colorPrimary">@color/primary_material_light</item>
<item name="colorAccent">@color/accent_material_light</item>
</style>
要暗控件使用下面的主題,使用光的主題。確保將primaryColor設置爲深色,音量欄會根據primaryColor自動設置爲明/暗。
<style name="CastThemeMediaRouter" parent="Theme.MediaRouter.Light.DarkControlPanel">
<item name="colorPrimary">@color/black</item>
</style>
謝謝!我會試試看。 – Menyetur
這個解決方案對我來說適用於MediaRouteChooserDialog,而不是MediaRouteControllerDialog。我在更多細節上做了簡短的介紹:http://explod.io/setting-the-theme-of-mediaroutechooserdialog/ –
阿里似乎在CastConfiguration上添加了'setMediaRouteDialogFactory',因爲這已經被回答了。所以你可以用你自己的主題創建你自己的工廠,並將它傳遞給CastConfiguration,它將被對話框使用 –