Activity按返回键提示2秒内再按退出

private long firstTime;
@Override
public void onBackPressed() {
    long secondTime = System.currentTimeMillis();
    if (secondTime - firstTime > 2000) {
        SnackbarManager.show(com.nispok.snackbar.Snackbar.with(getApplicationContext()).text("再按一次退出"), this);
        firstTime = secondTime;
    } else {
        finish();
    }
}

SnackbarManager报错可以在buld.gradle里面dependencies添加一行
compile "com.nispok:snackbar:2.11.0"

你可能感兴趣的:(Android界面)