AndroidStudio实现侧滑返回

gradle引用

compile 'me.imid.swipebacklayout.lib:library:1.1.0'

 然后引入工具类

import android.os.Bundle;

import me.imid.swipebacklayout.lib.SwipeBackLayout;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by Administrator on 2018/11/17 0017.
 */
public class BaseActivity extends SwipeBackActivity{
    private SwipeBackLayout mSwipeBackLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 可以调用该方法,设置是否允许滑动退出
        setSwipeBackEnable(true);

        mSwipeBackLayout = getSwipeBackLayout();

        // 设置滑动方向,可设置EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM
        mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);

        // 滑动退出的效果只能从边界滑动才有效果,如果要扩大touch的范围,可以调用这个方法
        mSwipeBackLayout.setEdgeSize(200);
    }

}

 

然后在需要实现侧滑返回的地方集成BaseActivity就可以,AppTheme需设置:

  true
  true

 

你可能感兴趣的:(AndroidStudio)