我有一个扩展片段的类。我有一个滑动抽屉,我想做的是,如果滑动抽屉打开,那么当用户触摸滑动抽屉外部时,它应该自动关闭。我的手动打开和关闭代码如下:
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);
}
});
我怎样才能做到这一点?