android – 在操作栏中显示Chromecast的MediaRouteButton

前端之家收集整理的这篇文章主要介绍了android – 在操作栏中显示Chromecast的MediaRouteButton前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
支持Chromecast的Netflix和YouTube应用在操作栏中显示MediaRouteButton,但 Sender App Tutorial显示如何在布局中显示它.如何在操作栏中显示它?

解决方法

您可以将其添加到操作栏菜单中,在操作栏中显示它:
<item
    android:id="@+id/action_mediaroute"
    android:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
    android:actionViewClass="android.support.v7.app.MediaRouteButton"
    android:showAsAction="always"
    android:title="@string/action_chromecast"/>

然后在onCreateOptionsMenu中提供初始化:

public boolean onCreateOptionsMenu( Menu menu ) {

    getMenuInflater().inflate( R.menu.main,menu );

    MenuItem mediaRouteItem = menu.findItem( R.id.action_mediaroute );
    mMediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView();

    mCastContext = new CastContext( getApplicationContext() );
    MediaRouteHelper.registerMinimalMediaRouteProvider( mCastContext,this );
    mMediaRouter = MediaRouter.getInstance( getApplicationContext() );
    mMediaRouteSelector = MediaRouteHelper.buildMediaRouteSelector( MediaRouteHelper.CATEGORY_CAST );
    mMediaRouteButton.setRouteSelector( mMediaRouteSelector );
    mMediaRouterCallback = new MyMediaRouterCallback();

    return true;
}
原文链接:https://www.f2er.com/android/317562.html

猜你在找的Android相关文章