Android 向右滑返回,退出当前activity
生活随笔
收集整理的這篇文章主要介紹了
Android 向右滑返回,退出当前activity
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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);} } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Android 向右滑返回,退出当前activity的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RabbitMQ消息确认机制
- 下一篇: 「HenCoder Plus」Andro