MenuItems(MediaRouterActoinProvider) are not being displayed from FragmentActivity

69 views Asked by At

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?

2

There are 2 answers

0
CommonsWare On

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.

0
MineConsulting SRL On

You should set setHasOptionsMenu(true); in your fragment onCreate