demo链接:https://download.csdn.net/download/meixi_android/10826597

实现效果:

7186e099e3b517ac5141e8db5cec4025.png

纯原生类实现方法:

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文件夹下

0422138c3040858212619a06c9008660.png

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);

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐