问题
I getting following error
This SlidingMenu appears to already be attached
This my source code
SlidingMenu menu = new SlidingMenu(this, SlidingMenu.SLIDING_WINDOW);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.menu);
I have used sliding menu library by jfeinstein
I want to slide menu with actionbar
. Please help me.
回答1:
Problem
From the SlidingMenu.java in attachToActivity method
if (getParent() != null)
throw new IllegalStateException("This SlidingMenu appears to already be attached");
here getParent is not null because you already assigned SlidingMenu.SLIDING_WINDOW when you create object of SlidingMenu.
e.g. SlidingMenu menu = new SlidingMenu(this, SlidingMenu.SLIDING_WINDOW);
above line of code calls attachToActivity. see in code
public SlidingMenu(Activity activity, int slideStyle) {
this(activity, null);
this.attachToActivity(activity, slideStyle);
}
So you are adding menu to layout twice. And that is the cause of problem.
Solution use one of the following.
Use below constructor
SlidingMenu menu = new SlidingMenu(this);
OR
- remove menu.attachToActivity(); line
回答2:
I met the same question. There is a R.java file in com.jeremyfeinstein.slidingmenu.lib,you might miss it. You can copy it from other SlidingMenu project into gen folder.
来源:https://stackoverflow.com/questions/25779814/this-slidingmenu-appears-to-already-be-attached-android