android.view.MenuItem android.view.MenuItem.setVisible(boolean)'在null对象引用上

时间:2015-11-01 15:57:41

标签: android xml menu

public boolean onPrepareOptionsMenu(Menu menu) {
        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
        menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
} 
<menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@+id/action_websearch"
        android:icon="@drawable/action_search"
        android:title="@string/action_websearch"
        android:showAsAction="ifRoom|withText"/>
</menu>

0 个答案:

没有答案