android 界面右滑关闭,Android 向右滑返回,退出当前activity
demo链接:https://download.csdn.net/download/meixi_android/10826597实现效果: 纯原生类实现方法:1、自定义侧滑基类SwipeBackActivitypublic class SwipeBackActivity extends FragmentActivity implements SwipeBackActivityBase {priva
demo链接:https://download.csdn.net/download/meixi_android/10826597
实现效果:
纯原生类实现方法:
1、自定义侧滑基类SwipeBackActivity
public class SwipeBackActivity extends FragmentActivity implements SwipeBackActivityBase {
private SwipeBackActivityHelper mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHelper = new SwipeBackActivityHelper(this);
mHelper.onActivityCreate();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mHelper.onPostCreate();
}
@Override
public View findViewById(int id) {
View v = super.findViewById(id);
if (v == null && mHelper != null)
return mHelper.findViewById(id);
return v;
}
@Override
public SwipeBackLayout getSwipeBackLayout() {
return mHelper.getSwipeBackLayout();
}
@Override
public void setSwipeBackEnable(boolean enable) {
getSwipeBackLayout().setEnableGesture(enable);
}
@Override
public void scrollToFinishActivity() {
Utils.convertActivityToTranslucent(this);
getSwipeBackLayout().scrollToFinishActivity();
}
}
2、复制demo中attrs文件及资源文件到values文件夹下
3、base类继承侧换基类即可
public class BaseFragmentActivity extends SwipeBackActivity {
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
private String pageFunction = new String();
/**
* 设置页面的功能
*
* @param pageFunction 功能的详细说明
*/
public void setPageFunction(String pageFunction) {
this.pageFunction = pageFunction;
}
}
4、创建第二个activity。即可实现侧换返回上一个页面
public class TwoActivity extends BaseFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.twoactivity);
}
}
更多推荐
所有评论(0)