0
votes

I have a program and I want to implement a sliding menu.

First I tryed Navigation Drawer Navigation Drawer which is what I basically want because:

1) It doesn't push the screen, it cover it 2) When I click on button up left it opens the menu 3) When I try to click on the screen to another

But on the other hand:

I don't want to have a button up left, I want the user to click a button from the screen and every time a different sliding menu comes up.

I tryed also jfeinstein10 Sliding Menu , but it doesn't cover the screen it only push it away and they have told me that it's not possible to change that. But on other hand, it is easy and better on some ways.

So any ideas how to 1) not have up left icon/button and 2) how to handle the navigation drawer with a button?

Edit:

I want to have a sliding menu that covers the screen not to push the screen

3

3 Answers

0
votes

Why don't you set a ViewGroup in the Navigation Drawer such as LinearLayout and addView with the correct view, created by inflating it. And removeAllViews() afterwards

on button click:

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.layout_i_want_in_my_drawer, null, false);
navigationViewGroup.addView(myView);
drawerToggle.openDrawer(Gravity.LEFT);

in actionbardrawertoggle's ondrawerclose():

navigationViewGroup.removeAllViews();

This code is not tested

first of all, follow the official tutorial: https://developer.android.com/training/implementing-navigation/nav-drawer.html

0
votes

There is slider.jar android library for this which give better result for navigation drawer

slide_me = new SimpleSideDrawer(this);

slide_me.setRightBehindContentView(R.layout.setting_activity);

and on button click use the following code

 slide_me.toggleRightDrawer(); // for open drawer from right side
 slide_me.toggleLeftDrawer(); // for open drawer from left side 
0
votes

Thanks dumazy I have found half of my answer and thanks to that Add button to activity with navigation drawer. The trick were in Gravity and to create a method in order to call it in my onClick Listener for the specific button.

Then the other half was just code deleting in the lines that the imagebutton up left was mentioned in order to open the Navigation Drawer.

Button onClick Listener:

    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            open();         }
    });

Method:

        public void open(){
    mDrawerLayout.openDrawer(Gravity.LEFT);
   }