I'm trying to implement the jfeinsteins sliding menu, however I'm having a problem getting a fragment to attach. The issue is that the layout is shown on the screen twice. I assume that this is because I setMenu and then do the replace (adding it again).
Could anyone provide some pointers please.
public void configureSlidingMenu()
{
// configure the SlidingMenu
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setFadeDegree(0.35f);
menu.setBehindOffset(120);
menu.setMenu(R.layout.fragment_slideoutmenu);
getFragmentManager()
.beginTransaction()
.replace(R.id.slideOutMenu, new SlideOutMenu())
.commit();
}
I did this in my application...
Created a class Util like this:
public class Util {
public static void atachLeftMenu(final Activity pActivity){
final SlidingMenu menu = new SlidingMenu(pActivity);
menu.setMode(SlidingMenu.LEFT);
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(pActivity, SlidingMenu.SLIDING_WINDOW);
menu.setMenu(R.layout.side_menu);
( (ListView)(menu.findViewById(R.id.side_menu_list)) ).setAdapter(new leftMenuAdapter(pActivity));
( (ListView)(menu.findViewById(R.id.side_menu_list)) ).setOnItemClickListener( new DrawerItemClickListener(pActivity));
//Set menu options and values
}
}
And in every Activity i just call the Util's "atachLeftMenu" method.
Util.atachLeftMenu(this);
If you want to do it within a fragment you'll still have to pass it the activity so you could do something like this:
Util.atachLeftMenu(getActivity());
Related
First of all I am sorry to ask repeated questions. As this has been asked before but some how I could not understand properly.
I found a good solutions here. I followed and could add library to my project. Now I need to add left and right sliding menus to my project without action-bar. Here is the picture-
If I click any of the selected button then it should open the respective sliding page(once at a time) at the specific sides. Something like -
currently -
I am able to generate one side of the menu bar. It is working with sliding only. -
public class MainActivity extends FragmentActivity {
ViewPager viewPager;
PagerAdapter adapter;
CirclePageIndicator mIndicator;
private int mWidthScreen;
private int mHeightScreen;
private Bundle bundle;
private List<Fragment> frgScreens;
private int selectedtheme;
private Handler mHandler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from viewpager_main.xml
setContentView(R.layout.viewpager_main);
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
}
Now I want in both sides and should open menu by clicking the button
Any help will be appreciated. Please feel free to ask any queries.
Well Finally I did it. Here mBtnMenu is an ImageView.
mBtnMenu = (ImageView) findViewById(R.id.btnMenu);
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(500);
menu.setMenu(R.layout.menu_frame);
mBtnMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// menu.showMenu();
menu.toggle();
}
});
by default jfeinstein SlidingMenu move content to view slide menu layout, but i dont like that and i want to view slide menu without move content and top of all layouts.
in this below screen shot i like number 2
Default settings are :
public class SlidingExample extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.attach);
// set the content view
setContentView(R.layout.content);
// configure the SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
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);
}
}
and i'm could not find whats setting view slide menu top of all layouts ans widgets after any testing attachToActivity
wild guess (I don't use jFeinstein)..
when the slider activates, to remove the 'hamburger' icon from the ABar get rid of "home_as_up"...
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_USE_LOGO |ActionBar.DISPLAY_HOME_AS_UP,
ActionBar.DISPLAY_HOME_AS_UP
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_USE_LOGO);
I created a sliding menu with the library https://github.com/jfeinstein10/SlidingMenu. I created my own login view instead of slide menu succesfully with the code
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
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.setSecondaryMenu(R.layout.login);
}}
Now I want to make some action in login.SO how can I do this.I tried within the same main activty. but it force closed, how can I do some action in login and where should I code ?? I am new to android so please help me and thanks :)
I had the same problem.Please check Slidingmenu.java in the library and make your code in function public void setsecondarymenu()
eg: if you want to settext to a textview
public void setSecondaryMenu(int res) {
setSecondaryMenu(LayoutInflater.from(getContext()).inflate(res, null));
TextView tv=(TextView)findViewById(R.id.tv);
tv.setText("helloo i got it :)");
}
make sure that u have a layout in library that you want to view
hope this will help you :)
I begin to use a slidingMenu. In my application I have a header with button. when I move it sliding, than my header move too. But I want, than my header do not move, and sliding menu move under header. My header is not actionBar, usual layout.
// configure the SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
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);
How I can do what I want?
You have to assign a button to action toggle from sliding.
findViewById(R.id.buttonToggle).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
getSlidingMenu().toggle(true);
}
});
I have an activity, where using the Sliding Menu library, i try to create 2 sliding menus.
This is the code i tried:
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
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.tutorial_layout);
rightSlide = new HelpFragment();
t.replace(R.id.slidingList2, rightSlide);
t.commit();
menu.setSecondaryMenu(R.layout.log_history);
leftSlide = new LogHistory();
t.replace(R.id.loghistorycon, leftSlide);
t.commit();
Now i get a ANR error, and Logcat says, that the FragmentTransaction t, has already been commited.
I looked at the example from: github.com/jfeinstein10/SlidingMenu and it allows him to do 2 commit's:
setContentView(R.layout.content_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new SampleListFragment())
.commit();
getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_two);
getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame_two, new SampleListFragment())
.commit();
What am I doing wrong? i just can't see the difference
Change your above code as below
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
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.tutorial_layout);
rightSlide = new HelpFragment();
t.replace(R.id.slidingList2, rightSlide);
t.commit();
t = this.getSupportFragmentManager().beginTransaction();
menu.setSecondaryMenu(R.layout.log_history);
leftSlide = new LogHistory();
t.replace(R.id.loghistorycon, leftSlide);
t.commit();
For a FragmentTransaction, you can have only one commit. In your code you created a FragmentTransaction object and called commit once for rightSlide. So t is not usable for transactions anymore. So you have create another FragmentTransaction as I have done in the above code. I hope this will work for you.
#LLL
Following code is working Properly to me.i hope,it help u more...
SlidingMenu slidingMenu = getSlidingMenu();slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
slidingMenu.setFadeDegree(0.35f);
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
slidingMenu.setMenu(R.layout.profile);
slidingMenu.setSecondaryMenu(R.layout.nextactivity);
Button csButton=(Button)findViewById(R.id.txtx);
inside csButton onclick listener just need to call slidingMenu.showSecondaryMenu();
and, Button csButton1=(Button)findViewById(R.id.button1);
inside csButton1 onclick listener just need to call slidingMenu.showMenu();