Fix bug 5396097 - menu theme consistency
Fix a bug where action bar menus were using the wrong context to inflate stock views. This was causing them to use the action bar's themed widget context instead of the current theme's specific action bar items. Note that action views in the menu will still be inflated using the themed widget context. This can produce some weird side effects if the action views use theme attributes relating to these action bar item attributes. Change-Id: Ied3614d1fedb10a0f5366bbe7b90cd5f2f1ff969
This commit is contained in:
@ -31,9 +31,6 @@ import android.view.View;
|
||||
import android.view.View.MeasureSpec;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -71,8 +68,8 @@ public class ActionMenuPresenter extends BaseMenuPresenter
|
||||
final PopupPresenterCallback mPopupPresenterCallback = new PopupPresenterCallback();
|
||||
int mOpenSubMenuId;
|
||||
|
||||
public ActionMenuPresenter() {
|
||||
super(com.android.internal.R.layout.action_menu_layout,
|
||||
public ActionMenuPresenter(Context context) {
|
||||
super(context, com.android.internal.R.layout.action_menu_layout,
|
||||
com.android.internal.R.layout.action_menu_item_layout);
|
||||
}
|
||||
|
||||
@ -98,7 +95,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter
|
||||
int width = mWidthLimit;
|
||||
if (mReserveOverflow) {
|
||||
if (mOverflowButton == null) {
|
||||
mOverflowButton = new OverflowMenuButton(mContext);
|
||||
mOverflowButton = new OverflowMenuButton(mSystemContext);
|
||||
final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||
mOverflowButton.measure(spec, spec);
|
||||
}
|
||||
@ -215,7 +212,7 @@ public class ActionMenuPresenter extends BaseMenuPresenter
|
||||
|
||||
if (hasOverflow) {
|
||||
if (mOverflowButton == null) {
|
||||
mOverflowButton = new OverflowMenuButton(mContext);
|
||||
mOverflowButton = new OverflowMenuButton(mSystemContext);
|
||||
}
|
||||
ViewGroup parent = (ViewGroup) mOverflowButton.getParent();
|
||||
if (parent != mMenuView) {
|
||||
|
@ -29,8 +29,10 @@ import java.util.ArrayList;
|
||||
* be reused if possible when items change.
|
||||
*/
|
||||
public abstract class BaseMenuPresenter implements MenuPresenter {
|
||||
protected Context mSystemContext;
|
||||
protected Context mContext;
|
||||
protected MenuBuilder mMenu;
|
||||
protected LayoutInflater mSystemInflater;
|
||||
protected LayoutInflater mInflater;
|
||||
private Callback mCallback;
|
||||
|
||||
@ -44,10 +46,13 @@ public abstract class BaseMenuPresenter implements MenuPresenter {
|
||||
/**
|
||||
* Construct a new BaseMenuPresenter.
|
||||
*
|
||||
* @param context Context for generating system-supplied views
|
||||
* @param menuLayoutRes Layout resource ID for the menu container view
|
||||
* @param itemLayoutRes Layout resource ID for a single item view
|
||||
*/
|
||||
public BaseMenuPresenter(int menuLayoutRes, int itemLayoutRes) {
|
||||
public BaseMenuPresenter(Context context, int menuLayoutRes, int itemLayoutRes) {
|
||||
mSystemContext = context;
|
||||
mSystemInflater = LayoutInflater.from(context);
|
||||
mMenuLayoutRes = menuLayoutRes;
|
||||
mItemLayoutRes = itemLayoutRes;
|
||||
}
|
||||
@ -62,7 +67,7 @@ public abstract class BaseMenuPresenter implements MenuPresenter {
|
||||
@Override
|
||||
public MenuView getMenuView(ViewGroup root) {
|
||||
if (mMenuView == null) {
|
||||
mMenuView = (MenuView) mInflater.inflate(mMenuLayoutRes, root, false);
|
||||
mMenuView = (MenuView) mSystemInflater.inflate(mMenuLayoutRes, root, false);
|
||||
mMenuView.initialize(mMenu);
|
||||
updateMenuView(true);
|
||||
}
|
||||
@ -138,7 +143,7 @@ public abstract class BaseMenuPresenter implements MenuPresenter {
|
||||
* @return The new item view
|
||||
*/
|
||||
public MenuView.ItemView createItemView(ViewGroup parent) {
|
||||
return (MenuView.ItemView) mInflater.inflate(mItemLayoutRes, parent, false);
|
||||
return (MenuView.ItemView) mSystemInflater.inflate(mItemLayoutRes, parent, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,8 +43,8 @@ public class IconMenuPresenter extends BaseMenuPresenter {
|
||||
private static final String VIEWS_TAG = "android:menu:icon";
|
||||
private static final String OPEN_SUBMENU_KEY = "android:menu:icon:submenu";
|
||||
|
||||
public IconMenuPresenter() {
|
||||
super(com.android.internal.R.layout.icon_menu_layout,
|
||||
public IconMenuPresenter(Context context) {
|
||||
super(context, com.android.internal.R.layout.icon_menu_layout,
|
||||
com.android.internal.R.layout.icon_menu_item_layout);
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ public class ActionBarContextView extends AbsActionBarView implements AnimatorLi
|
||||
});
|
||||
|
||||
final MenuBuilder menu = (MenuBuilder) mode.getMenu();
|
||||
mActionMenuPresenter = new ActionMenuPresenter();
|
||||
mActionMenuPresenter = new ActionMenuPresenter(mContext);
|
||||
mActionMenuPresenter.setReserveOverflow(true);
|
||||
|
||||
final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
|
||||
|
@ -373,7 +373,7 @@ public class ActionBarView extends AbsActionBarView {
|
||||
}
|
||||
}
|
||||
if (mActionMenuPresenter == null) {
|
||||
mActionMenuPresenter = new ActionMenuPresenter();
|
||||
mActionMenuPresenter = new ActionMenuPresenter(mContext);
|
||||
mActionMenuPresenter.setCallback(cb);
|
||||
mActionMenuPresenter.setId(com.android.internal.R.id.action_menu_presenter);
|
||||
mExpandedMenuPresenter = new ExpandedActionViewMenuPresenter();
|
||||
|
Reference in New Issue
Block a user