1. 程式人生 > >Android 滑動返回上一頁

Android 滑動返回上一頁

1.新增依賴:implementation ‘me.imid.swipebacklayout.lib:library:1.1.0’ (如果新增失敗,請試著翻牆後再試)

2.繼承 SwipeBackLayout ,獲取SwipeBackLayout ,新增滑動返回的方向。

public class LoginActivity extends SwipeBackActivity{

  @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_activity);
  
   SwipeBackLayout  mSwipeBackLayout = getSwipeBackLayout();  //獲取SwipeBackLayout
    int edgeFlag = SwipeBackLayout.EDGE_LEFT;//設定從左滑動返回 
    mSwipeBackLayout.setEdgeTrackingEnabled(edgeFlag); //開啟滑動返回
   
}

}
3. 效果
在這裡插入圖片描述
更多請瀏覽 https://github.com/ikew0ng/SwipeBackLayout