标签:loop nload vat build mono navig string back layout
展示的效果就这样简单就看你是有那个需求了。SnackBar的创建过程使用了Builder设计模式,有不同需求的可以更具需求结合代码创建出需要的效果。
分享个退出提示工具类DoubleClickExitHelper.java
package miuyongjun.twentysix.utils; import android.app.Activity; import android.os.Handler; import android.os.Looper; import android.support.design.widget.Snackbar; import android.view.KeyEvent; import android.view.View; /** * 双击退出工具类 * * @author wxc */ public class DoubleClickExitHelper { private final Activity mActivity; private boolean isOnKeyBacking; private Handler mHandler; private Snackbar snackbar; public DoubleClickExitHelper(Activity activity) { mActivity = activity; mHandler = new Handler(Looper.getMainLooper()); AppManager.getAppManager().addActivity(mActivity); } /** * Activity onKeyDown事件 */ public boolean onKeyDown(int keyCode, View view) { if (keyCode != KeyEvent.KEYCODE_BACK) { return false; } if (isOnKeyBacking) { mHandler.removeCallbacks(onBackTimeRunnable); if (snackbar != null) { snackbar.dismiss(); } AppManager.getAppManager().AppExit(mActivity); return true; } else { isOnKeyBacking = true; if (snackbar == null) { snackbar = Snackbar.make(view, "再次点击退出应用", 2000); } snackbar.show(); mHandler.postDelayed(onBackTimeRunnable, 2000); return true; } } private Runnable onBackTimeRunnable = new Runnable() { @Override public void run() { isOnKeyBacking = false; if (snackbar != null) { snackbar.dismiss(); } } }; }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean flag = true;
if (keyCode == KeyEvent.KEYCODE_BACK) {
return mDoubleClickExitHelper.onKeyDown(keyCode, navigationView);
}
return flag;
}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow
标签:loop nload vat build mono navig string back layout
原文地址:https://www.cnblogs.com/skiwnchhw/p/10349230.html