Reputation: 151
I need to display MediaRouterActionProvider
as a menu item and have it displayed in the action bar of Main Activity which extends FragmentActivity()
;
The setup:
mainMenu.xml
<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
private void setUpActionBar() {
mActionBar = getActionBar();
mActionBar.setLogo(R.drawable.ic_launcher);
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.setDisplayShowTitleEnabled(false);
mActionBar.setTitle("MediaRouter");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
I’m unable to display the menu item in actionBar. Is there a way in which i can get this working other that extending it to ActionBarActivity
?
Upvotes: 1
Views: 74
Reputation: 1006869
Is there a way in which i can get this working other that extending it to ActionBarActivity?
The v7
edition of the MediaRouteActionProvider
only works with the appcompat-v7
version of the action bar, which in turn requires ActionBarActivity
, Theme.AppCompat
, and kin.
I have a cross-port of MediaRouteActionProvider
that works with the native action bar.
Upvotes: 2
Reputation: 2340
You should set setHasOptionsMenu(true);
in your fragment onCreate
Upvotes: 0