有人可以帮我点击MediaRouteButton后出现的样式对话框吗?
灰色背景上显示的白色文字看起来不太好。
android.support.v7.app.MediaRouteButton
包含在带有样式
的父级中<FrameLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
(我知道我应该在这里使用工具栏,但它不符合我的要求)
适用于MediaRouteButton,后者变为白色,但对对话框样式没有影响。
我试着查看Google提供的示例应用,但我找不到任何可以帮助我的内容。 Link to sample app styles
我目前的主题:
<style name="Theme.AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>//Blue
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>//dark blue
<item name="colorAccent">@color/colorPrimary</item>//blue
</style>
答案 0 :(得分:5)
找到适合我的解决方案。
首先,您必须在MediaRouteButton上设置自定义MediaRouteDialogFactory
mMediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
MediaRouteButton mediaRouteButton = (MediaRouteButton) mMediaRouteMenuItem.getActionView()
mediaRouteButton.setDialogFactory(new ThemeableMediaRouteDialogFactory());
因为默认的MediaRouteDialogFactory将始终创建非主题对话框
@NonNull
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new MediaRouteControllerDialogFragment();
}
将导致
public MediaRouteControllerDialog onCreateControllerDialog(
Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context);
}
但是还有一个主题构造函数MediaRouteControllerDialog(Context context, int theme) 这不是从原始MediaRouteDialogFactory调用的。
所以你的ThemeableMediaRouteDialogFactory应该看起来像这样
public class ThemeableMediaRouteDialogFactory extends MediaRouteDialogFactory {
@NonNull
@Override
public MediaRouteChooserDialogFragment onCreateChooserDialogFragment() {
return new ThemeableMediaRouterChooserDialogFragment();
}
@NonNull
@Override
public MediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new ThemeableMediaRouteControllerDialogFragment();
}
}
与
public class ThemeableMediaRouterChooserDialogFragment extends MediaRouteChooserDialogFragment {
@Override
public MediaRouteChooserDialog onCreateChooserDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteChooserDialog(context, R.style.CastChooserDialogTheme);
}
}
和
public class ThemeableMediaRouteControllerDialogFragment extends MediaRouteControllerDialogFragment {
@Override
public MediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
return new MediaRouteControllerDialog(context, R.style.CastControllerDialogTheme);
}
}
您的主题/风格也可以自定义
<style name="DarkDialogTheme" parent="Theme.AppCompat.Dialog">
<item name="colorPrimary">@color/charcoal_grey</item>
<item name="colorPrimaryDark">@color/charcoal_grey_dark</item>
<item name="colorAccent">@color/pumpkin_orange</item>
<item name="android:windowBackground">@color/dark_grey</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="CastChooserDialogTheme" parent="DarkDialogTheme">
<item name="android:windowNoTitle">false</item>
<item name="mediaRouteChooserPrimaryTextStyle">@style/MediaRouteChooserPrimaryText</item>
<item name="mediaRouteChooserSecondaryTextStyle">@style/MediaRouteChooserSecondaryText</item>
</style>
<style name="CastControllerDialogTheme" parent="DarkDialogTheme">
<item name="MediaRouteControllerWindowBackground">@color/dark_grey</item>
<item name="colorPrimary">@color/dark_grey</item>
<item name="mediaRouteCloseDrawable">@drawable/ic_dialog_close_dark</item>
<item name="mediaRouteControllerTitleTextStyle">@style/Widget.MediaRouter.ControllerText.Title.Dark</item>
</style>