gpt4 book ai didi

android - 单击 MediaRouteButton 后的样式对话框

转载 作者:太空狗 更新时间:2023-10-29 16:13:00 26 4
gpt4 key购买 nike

您好,有人可以帮我处理单击 MediaRouteButton 后出现的样式对话框吗? Chromecast dialog

灰色背景上显示的白色文本看起来不太好。

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>

最佳答案

找到了适合我的解决方案。

首先你必须在你的 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>

关于android - 单击 MediaRouteButton 后的样式对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38997276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com