i have a class which extends fragment. i have a slidingdrawer which i want to do is, if the slidingdrawer is opened then when user touch outside the slidingdrawer, it should automatically closed. my code for manually open and close is like:
final Button slideButton;
final SlidingDrawer slidingDrawer;
slideButton = (Button) view.findViewById(R.id.slideButton);
slidingDrawer = (SlidingDrawer) view.findViewById(R.id.SlidingDrawer);
slideButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(slidingDrawer.isOpened())
slidingDrawer.animateClose();
else
slidingDrawer.animateOpen();
}
});
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
slideButton.setBackgroundResource(R.drawable.openarrow);
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
@Override
public void onDrawerClosed() {
slideButton.setBackgroundResource(R.drawable.closearrow);
}
});
how can i achieve that ??
I'm not sure how you're implementing the sliding drawer, but you can do this similar to closing the keyboard with a touch outside, like this:
https://stackoverflow.com/a/11656129/901309
But instead of closing the keyboard, close your sliding drawer. You'll need to pass the setupUI() method the View (LinearLayout, RelativeLayout, etc.) that contains everything except the sliding drawer.
Also, remove the "if(!(view instanceof EditText))" check.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.