一、概述:
在项目中学习到类似QQ向左滑动关闭Activity的开源库——SwipeBackLayout,分享记录一下
二、使用:
1.添加依赖:
compile 'me.imid.swipebacklayout.lib:library:1.0.0'
2.让BaseActivity继承SwipeBaseActivty
public class BaseActivity extends SwipeBackActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base);
}
}
3.给Activity设置滑动方式:(一般滑动方式有四种:All,Right,Left,Bottom。不做任何处理默认为向左滑动,也可以设置为不滑动)
SwipeBackLayout backLayout = getSwipeBackLayout();
设置为向所有方向都可以滑动
backLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_ALL);
//设置为向左滑动
backLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
//设置为向右滑动
backLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_RIGHT);
//设置为向下滑动
backLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_BOTTOM);
//设置为不能滑动
backLayout.setEnableGesture(false);
4.最后给Activity设置主题,防止滑动的时候是黑色背景:
<style name="AppBackTheme" parent="@style/AppTheme">
<item name="android:windowIsTranslucent">true</item>
</style>