demo链接:https://download.csdn.net/download/meixi_android/10826597
实现效果:
纯原生类实现方法:
1、自定义侧滑基类SwipeBackActivity
public class SwipeBackActivity extends FragmentActivity implements SwipeBackActivityBase {private SwipeBackActivityHelper mHelper;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);mHelper = new SwipeBackActivityHelper(this);mHelper.onActivityCreate();}@Overrideprotected void onPostCreate(Bundle savedInstanceState) {super.onPostCreate(savedInstanceState);mHelper.onPostCreate();}@Overridepublic View findViewById(int id) {View v = super.findViewById(id);if (v == null && mHelper != null)return mHelper.findViewById(id);return v;}@Overridepublic SwipeBackLayout getSwipeBackLayout() {return mHelper.getSwipeBackLayout();}@Overridepublic void setSwipeBackEnable(boolean enable) {getSwipeBackLayout().setEnableGesture(enable);}@Overridepublic void scrollToFinishActivity() {Utils.convertActivityToTranslucent(this);getSwipeBackLayout().scrollToFinishActivity();} }
2、复制demo中attrs文件及资源文件到values文件夹下
3、base类继承侧换基类即可
public class BaseFragmentActivity extends SwipeBackActivity {@Overrideprotected void onCreate(Bundle arg0) {super.onCreate(arg0);}@Overridepublic void onResume() {super.onResume();}@Overridepublic void onPause() {super.onPause();}@Overrideprotected 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 {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.twoactivity);} }