4

As we set menuItem as the MediaRouteButton,

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.cast_item_menu, menu);
    mediaRouteMenuItem = CastButtonFactory.setUpMediaRouteButton(getApplicationContext(), menu, R.id.media_route_menu_item);
    return true;
}

Is there any way to set a button or an ImageButton as the MediaRouteButton in android?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Choxmi
  • 1,584
  • 4
  • 29
  • 47
  • 1
    Have a look at [This](https://stackoverflow.com/questions/19278319/how-do-i-change-the-style-of-the-mediaroutebutton-in-the-actionbar) if you haven't already . – ADM Dec 19 '17 at 12:33

1 Answers1

7

Finally came up with a solution. Hope this will help someone.

Layout XML file

Create a MediaRouteButton using xml.

<android.support.v7.app.MediaRouteButton
        android:id="@+id/cast"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_alignParentRight="true"
        android:scaleType="center"
        android:src="@drawable/ic_google_cast_logo"
        android:visibility="visible" />

This will create the button you need. Then use it in your activity.

Activity

Instantiate the button and set the media button this way.

    MediaRouteButton mediaRouteButton = (MediaRouteButton)findViewById(R.id.cast);
    CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),mediaRouteButton);

Happy coding...(y)

Choxmi
  • 1,584
  • 4
  • 29
  • 47