造型CHROMECAST MediaRoute按钮 [英] Styling ChromeCast MediaRoute button

查看:365
本文介绍了造型CHROMECAST MediaRoute按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到MediaRoute按钮显示为我的动作条实心白。

I can't seem to get the MediaRoute button to show up as 'white' in my solid ActionBar.

我的问题是:我们怎样才能在样式按钮MediaRoute亮或暗,不改变绘制名

My question is this: How can we style the MediaRoute button light or dark, without changing drawable names?

在看一个类似的问题在这里:<一href=\"http://stackoverflow.com/questions/19278319/how-do-i-change-the-style-of-the-mediaroutebutton-in-the-actionbar\">How我改变MediaRouteButton的风格在ActionBar 的接受的解决方案就是使用你自己的一套MediaRoute可绘制的,并交换了姓名光与LT;?>暗

Looking at a similar question here: How do I change the style of the MediaRouteButton in the ActionBar? the accepted solution is just to use your own set of MediaRoute drawables, and swap the names light<>dark.

有关我的应用程序,我有3个截然不同的风格:轻动作条,暗动作条,光固动作条。我不能简单地交换绘制的名字,因为我需要黑暗和光前两个主题正确显示。为了正确显示固体动作条的内容,我在做这样的事情:这里找到(下面的例子:的 http://www.jayway.com/2014/06/02/android-theming-the-actionbar/ <​​/A>)

For my app, I have 3 distinct styles: light-ActionBar, dark-ActionBar, and light solid-ActionBar. I can'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'm doing something like this: (Following example found here: 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主题是既要保证动作条溢出图标下拉菜单背景显示为白色,而不是黑色。但是,它会导致MediaRoute按钮切换到它的黑暗为主题的绘项目,它不适合。

The ActionBarWidget theme is necessary to ensure the ActionBar overflow icon dropdown menu background shows up as white instead of black. However, it causes the MediaRoute button to change to it's dark-theme drawables, which does not suit.

我试着重写 Widget.MediaRouter.MediaRouteButton ,并迫使&LT;项目名称=externalRouteEnabledDrawable&GT; @绘制/ mr_ic_media_route_holo_dark&LT; /项目方式&gt; ,但没有我这样做有差别

I've tried overriding Widget.MediaRouter.MediaRouteButton and forcing <item name="externalRouteEnabledDrawable">@drawable/mr_ic_media_route_holo_dark</item>, but nothing I do makes a difference.

我们怎样才能在样式按钮MediaRoute亮或暗,不改变绘制的名字呢?
有一个简单的样式覆盖,我们可以设置我们自己的MediaRoute绘项目?

How can we style the MediaRoute button light or dark, without changing drawable names? Is there a simple style to override where we can set our own MediaRoute drawables?

推荐答案

请尝试以下操作:

menu.xml文件:

menu.xml:

<item
    android:id="@+id/media_route_menu_item"
    android:title="@string/media_route_menu_title"
    app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
    app:actionViewClass="com.???.MediaRouteButtonHoloDark"
    app:showAsAction="always" />

MediaRouteButtonHoloDark:

MediaRouteButtonHoloDark:

public class MediaRouteButtonHoloDark extends MediaRouteButton {

    public MediaRouteButtonHoloDark( Context context ) {
        this( context, null );
    }

    public MediaRouteButtonHoloDark( Context context, AttributeSet attrs ) {
        this( context, attrs, android.support.v7.mediarouter.R.attr.mediaRouteButtonStyle ); 
    }

    public MediaRouteButtonHoloDark( Context context, AttributeSet attrs, int defStyleAttr ) {
        super( getThemedContext(context), attrs, defStyleAttr);     
    }

    private static Context getThemedContext( Context context ) {
        context = new ContextThemeWrapper( context, android.support.v7.appcompat.R.style.Theme_AppCompat );
        return new ContextThemeWrapper( context,  android.support.v7.mediarouter.R.style.Theme_MediaRouter );

    }   
}

和地方在code:

...
MenuItem mediaRouteMenuItem = menu.findItem( R.id.media_route_menu_item );      
MediaRouteButton mediaRouteButton = (MediaRouteButton) MenuItemCompat.getActionView( mediaRouteMenuItem ); 
mediaRouteButton.setRouteSelector( mMediaRouteSelector );
...

这篇关于造型CHROMECAST MediaRoute按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆