Styling Chromecast Mediaroute Button
I can't seem to get the MediaRoute button to show up as 'white' in my solid ActionBar. My question is this: How can we style the MediaRoute button light or dark, without changing d
Solution 1:
Try the following:
menu.xml:
<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:actionViewClass="com.???.MediaRouteButtonHoloDark"
app:showAsAction="always" />
MediaRouteButtonHoloDark:
publicclassMediaRouteButtonHoloDarkextendsMediaRouteButton {
publicMediaRouteButtonHoloDark( Context context ) {
this( context, null );
}
publicMediaRouteButtonHoloDark( Context context, AttributeSet attrs ) {
this( context, attrs, android.support.v7.mediarouter.R.attr.mediaRouteButtonStyle );
}
publicMediaRouteButtonHoloDark( Context context, AttributeSet attrs, int defStyleAttr ) {
super( getThemedContext(context), attrs, defStyleAttr);
}
privatestatic Context getThemedContext( Context context ) {
context = newContextThemeWrapper( context, android.support.v7.appcompat.R.style.Theme_AppCompat );
returnnewContextThemeWrapper( context, android.support.v7.mediarouter.R.style.Theme_MediaRouter );
}
}
And somewhere in your code:
...
MenuItem mediaRouteMenuItem = menu.findItem( R.id.media_route_menu_item );
MediaRouteButton mediaRouteButton = (MediaRouteButton) MenuItemCompat.getActionView( mediaRouteMenuItem );
mediaRouteButton.setRouteSelector( mMediaRouteSelector );
...
Solution 2:
I got a similar problem with the null pointer exception also. I don't use the CastCompanionLibrary, but I solved it like this:
1.) Do not use the app:actionProviderClass in your menu definition.
<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_route_menu_title"
app:actionViewClass="com.???.MediaRouteButtonHoloDark"
app:showAsAction="always" />
2.) Search for the place where your code or the CCL tries to get the ActionProvider and if no ActionProvider is found then just search for the ActionView with the MediaRouteButton. Like this:
....
MenuItemmediaRouteMenuItem= menu.findItem( R.id.media_route_menu_item );
MediaRouteActionProvidermediaRouteActionProvider= (MediaRouteActionProvider) MenuItemCompat.getActionProvider( mediaRouteMenuItem );
if (null!=mediaRouteActionProvider) {
Log.i( TAG, "MediaRouteActionProvider found" );
mediaRouteActionProvider.setRouteSelector( mMediaRouteSelector );
return;
}
MediaRouteButtonmediaRouteButton= (MediaRouteButton) MenuItemCompat.getActionView( mediaRouteMenuItem );
if (null!=mediaRouteButton) {
Log.i( TAG, "MediaRouteButton found" );
mediaRouteButton.setRouteSelector( mMediaRouteSelector );
return;
}
....
I hope, this helps.
Post a Comment for "Styling Chromecast Mediaroute Button"