Merge "Fix menu popup rendering" into nyc-dev

This commit is contained in:
Deepanshu Gupta
2016-03-28 17:07:12 +00:00
committed by Android (Google) Code Review

View File

@@ -43,6 +43,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowCallback; import android.view.WindowCallback;
import android.widget.ActionMenuPresenter; import android.widget.ActionMenuPresenter;
import android.widget.ActionMenuView;
import android.widget.Toolbar; import android.widget.Toolbar;
import android.widget.Toolbar_Accessor; import android.widget.Toolbar_Accessor;
@@ -196,11 +197,16 @@ public abstract class FrameworkActionBarWrapper {
@Override @Override
protected void inflateMenus() { protected void inflateMenus() {
super.inflateMenus(); super.inflateMenus();
// Inflating the menus doesn't initialize the ActionMenuPresenter. Setting a fake menu // Inflating the menus isn't enough. ActionMenuPresenter needs to be initialized too.
// and then setting it back does the trick.
MenuBuilder menu = getMenuBuilder(); MenuBuilder menu = getMenuBuilder();
DecorToolbar decorToolbar = getDecorToolbar(); DecorToolbar decorToolbar = getDecorToolbar();
// Setting a menu different from the above initializes the presenter.
decorToolbar.setMenu(new MenuBuilder(getActionMenuContext()), null); decorToolbar.setMenu(new MenuBuilder(getActionMenuContext()), null);
// ActionMenuView needs to be recreated to be able to set the menu back.
ActionMenuPresenter presenter = getActionMenuPresenter();
if (presenter != null) {
presenter.setMenuView(new ActionMenuView(getPopupContext()));
}
decorToolbar.setMenu(menu, null); decorToolbar.setMenu(menu, null);
} }
@@ -255,7 +261,7 @@ public abstract class FrameworkActionBarWrapper {
@NonNull ActionBarView actionBarView) { @NonNull ActionBarView actionBarView) {
super(context, callback, new WindowDecorActionBar(decorContentRoot)); super(context, callback, new WindowDecorActionBar(decorContentRoot));
mActionBarView = actionBarView; mActionBarView = actionBarView;
mActionBar = ((WindowDecorActionBar) super.mActionBar); mActionBar = (WindowDecorActionBar) super.mActionBar;
mDecorContentRoot = decorContentRoot; mDecorContentRoot = decorContentRoot;
} }