这是我的布局:
<android.support.v7.app.MediaRouteButton
android:id="@+id/button_fling"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:background="@drawable/mr_ic_media_route_holo_light"
android:layout_height="wrap_content"
android:mediaRouteTypes="user"
android:layout_weight="1"
android:visibility="visible" />
这在我的活动中:
@覆盖
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(CastMediaControlIntent.categoryForCast(getString(R.string.app_id)))
.build();
mMediaRouterCallback = new MyMediaRouterCallback();
mMediaRouteButton = (MediaRouteButton) findViewById(R.id.button_fling);
mMediaRouteButton.setRouteSelector(mMediaRouteSelector);
button_fling2 = (ImageView)findViewById(R.id.button_fling2);
}
public class MyMediaRouterCallback extends MediaRouter.Callback {
public int mRouteCount =0;
@Override
public void onRouteAdded(MediaRouter router, RouteInfo route) {
Log.d(TAG, "onRouteAdded");
if (++mRouteCount == 1) {
// Show the button when a device is discovered.
Log.i(TAG,"MediaRoute is visible");
button_fling2.setVisibility(View.VISIBLE);
mMediaRouteButton.setVisibility(View.VISIBLE);
}
}
@Override
public void onRouteRemoved(MediaRouter router, RouteInfo route) {
Log.d(TAG, "onRouteRemoved");
if (--mRouteCount == 0) {
// Hide the button if there are no devices discovered.
Log.i(TAG,"MediaRoute is GONE");
button_fling2.setVisibility(View.GONE);
mMediaRouteButton.setVisibility(View.GONE);
}
}
}
ButtonFling2 是我用来测试 MyMediaRouterCallback 是否工作的 ImageView。它成功隐藏/显示 imageView。然而,button_fling(这是一个 mediaRouteButton 实例)没有显示任何内容。就好像它找不到 MediaRouteButton 的资源,因此它没有显示投射图标...有人修复过此问题或遇到过此问题吗?
我没有收到任何错误,它只是没有显示,但日志显示它是可见的,并且我用于测试的 ImageView 出现了。
在摆弄这个东西之后,我能够显示媒体路由器按钮。我不完全确定我做了什么,但我确实验证了 appid 并尝试使用我列入白名单的应用程序 ID。我重新安装了支持库。感谢大家对此提供的帮助!
我不是 100% 确定这是如何发生的,但我希望这可以帮助人们弄清楚或至少克服这个问题。 ActionBar 活动和非操作栏活动现在显示媒体路由器按钮! :)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)