user742030
user742030

Reputation:

Open a SlidingDrawer via button

How can I open a SlidingDrawer using a button not attached to it? In other words, I like to open it w/o the handle.

Upvotes: 3

Views: 5230

Answers (4)

Jared Burrows
Jared Burrows

Reputation: 55545

Im not sure if you still need help or not but I was just wondering the same thing.

"SlidingDrawer" is our object called "slider":

SlidingDrawer slider = (SlidingDrawer) findViewById(R.id.SlidingDrawer);

Call the method "open()", using our object name:

slider.open();

Example button that just opens the sliding drawer:

Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        slider.open();
    }
});

enter image description here

Upvotes: 2

Gunnar Karlsson
Gunnar Karlsson

Reputation: 28480

Calling .open() and .close() makes the drawer appear and disappear without animation. I don't know if this is generally the case - I tested this on 4.03 with the drawer in a RelativeLayout and it just popped into view without animation.

To make the SlidingDrawer open and close by sliding into the View when clicking a button, use:

slidingDrawer.animateOpen();

and

slidingDrawer.animateClose();

Upvotes: 5

KITT
KITT

Reputation: 240

You need to override the handle's touch method(s) and pass down the touch event to the button.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007554

Call open() on the SlidingDrawer.

Upvotes: 7

Related Questions