public class BackActivity extends SwipeBackActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_back);
ImmersionBar.with(this)
.titleBar(R.id.toolbar)
.navigationBarColor(R.color.colorPrimary)
.init();
SwipeBackLayout mSwipeBackLayout = getSwipeBackLayout();
mSwipeBackLayout.setEnabled(true);
// 设置滑动方向,可设置EDGE_LEFT, EDGE_RIGHT, EDGE_ALL, EDGE_BOTTOM
mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT);
// 滑动退出的效果只能从边界滑动才有效果,如果要扩大touch的范围,可以调用这个方法
mSwipeBackLayout.setEdgeSize(getWindowWidth2()/2);
Log.e("ZZP",getWindowWidth0()+","+getWindowWidth1()+","+getWindowWidth2()+","
+getWindowWidth3());
}
@Override
protected void onDestroy() {
super.onDestroy();
ImmersionBar.with(this).destroy();
}
int getWindowWidth0(){
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
return wm.getDefaultDisplay().getWidth();
}
int getWindowWidth1(){
WindowManager wm1 = this.getWindowManager();
return wm1.getDefaultDisplay().getWidth();
}
int getWindowWidth2(){
WindowManager manager = this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
}
int getWindowWidth3(){
Resources resources = this.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
return dm.widthPixels;
}
}
网友评论