cc5zhenhua
cc5zhenhua

Reputation: 145

MenuItem.mActionProvider is null

I add following Menu item:

on my mainactivity's onCreateOptionsMenu(Menu menu):

the mediaRouteItem.getActionView() can get the button successfully.but the ActionProvider is null. Please help a introduction why. Thanks a lot!

<item
android:id="@+id/action_mediaroute01"
android:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
android:actionViewClass="android.support.v7.app.MediaRouteButton"
android:showAsAction="always"
android:title="@string/hello_world"/>

-

public void onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem mediaRouteItem = menu.findItem( R.id.action_mediaroute01 );
    MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteItem);
}

Upvotes: 1

Views: 888

Answers (1)

cc5zhenhua
cc5zhenhua

Reputation: 145

Got the issue point after researching. Should not use android:actionProviderClass when we want to use objects in support library. Should take "http://schemas.android.com/apk/res-auto" namespace for the actionproviderClass attributes in menu item xml

Upvotes: 3

Related Questions