Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Button as MediaRouteButton?

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?

like image 690
Choxmi Avatar asked Oct 30 '25 05:10

Choxmi


1 Answers

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)

like image 114
Choxmi Avatar answered Nov 01 '25 19:11

Choxmi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!