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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With