I am trying to get a reference to the MediaRouteButton which is the cast icon and I am getting a null value all the time. Just wanted to see if anyone knows how to get a reference to this button. I am using a onGlobalLayoutListener to get notifications.
Asked
Active
Viewed 45 times
0
-
Could you explain (1) your use case and (2) are you using CCL? – Ali Naddaf Dec 03 '15 at 17:06
-
I am using the CCL Library but I am trying to use ShowcaseView https://github.com/amlcurran/ShowcaseView I can't get the showcase view to show. The problem is I am getting null. I can post a snippet but cannot post code because it is private company. – ronnie173 Dec 03 '15 at 20:41
-
`final View button = activity.getWindow().getDecorView().findViewById(R.id.media_route_menu_item);` ) This is what I am trying to call and it is returning null. – ronnie173 Dec 03 '15 at 20:45
1 Answers
0
If you are using CCL, you should be easily able to use ShowCaseView; take a look at the CastVideos-android app and see how it does it, basically you can use the callback onCastDeviceDetected()
to be notified when the cast button appears and then do something like:
Menu menu = mToolbar.getMenu();
View view = menu.findItem(R.id.media_route_menu_item).getActionView();
if (view != null && view instanceof MediaRouteButton) {
new ShowcaseView.Builder(this)
.setTarget(new ViewTarget(view))
.setContentTitle(R.string.touch_to_cast)
.build();
}
This assumes you have a ToolBar.
EDIT: If you have an ActionBar, try the following:
new ShowcaseView.Builder(this)
.setTarget(new ActionViewTarget(this, ActionViewTarget.Type.MEDIA_ROUTE_BUTTON))
.setContentTitle(R.string.touch_to_cast)
.build();
At some point, I had submitted a patch to ShowCaseView project to cover MediaRoute button so hopefully that still works; I haven't tried that lately since I am using Toolbar now.

Ali Naddaf
- 16,951
- 2
- 21
- 28
-
Yeah the problem is I don't have a toolbar. I am using an action bar. – ronnie173 Dec 04 '15 at 02:28
-