我似乎无法让MediaRoute按钮在我的实体ActionBar中显示为“白色” .
我的问题是:我们如何在不更改可绘制名称的情况下将MediaRoute按钮设置为浅色或深色?
在这里看一个类似的问题:How do I change the style of the MediaRouteButton in the ActionBar?接受的解决方案就是使用你自己的一套MediaRoute drawables,并交换名称light <> dark .
对于我的应用程序,我有3种不同的样式:light-ActionBar,dark-ActionBar和light solid-ActionBar . 我可以't simply swap the drawable names, as I need both dark and light to display correctly for the first two themes. In order to display the solid actionbar contents correctly, I'做这样的事情:(以下示例在这里找到:http://www.jayway.com/2014/06/02/android-theming-the-actionbar/)
//Parent Light.DarkActionBar should give white ActionBar icons
<style name="AppTheme.Solid.Light" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/Widget.Solid.ActionBar</item>
<item name="android:actionBarWidgetTheme">@style/ActionBarWidget</item>
.
.
//Make the ActionBar solid, but need to use 'inverse' to keep the icons/text white
<style name="Widget.Solid.ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
.
.
//**** THE ISSUE IS CAUSED BY USING THE FOLLOWING
//Make the ActionBar dropdown spinner items use the correct (white) theme as well
<style name="ActionBarWidget" parent="Theme.AppCompat.Light.DarkActionBar">
.
.
ActionBarWidget主题是必要的,以确保ActionBar溢出图标下拉菜单背景显示为白色而不是黑色 . 但是,它会导致MediaRoute按钮更改为它的暗主题drawable,这不适合 .
我已经尝试重写 Widget.MediaRouter.MediaRouteButton
并强制 <item name="externalRouteEnabledDrawable">@drawable/mr_ic_media_route_holo_dark</item>
,但我没有做任何改变 .
如何在不更改可绘制名称的情况下,将MediaRoute按钮设置为浅色或深色?是否有一种简单的样式可以覆盖我们可以设置自己的MediaRoute drawables的位置?
2 回答
请尝试以下方法:
menu.xml文件:
MediaRouteButtonHoloDark:
在代码的某处:
我也遇到类似的空指针异常问题 . 我不使用CastCompanionLibrary,但我解决了这个问题:
1.)不要在菜单定义中使用app:actionProviderClass .
2.)搜索代码或CCL尝试获取ActionProvider的位置,如果没有找到ActionProvider,则只需使用MediaRouteButton搜索ActionView . 像这样:
我希望这有帮助 .