Fragment中 监听Android 返回按钮事件
作者:互联网
@Override public void onResume() { super.onResume(); getView().setFocusableInTouchMode(true); getView().requestFocus(); getView().setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if(keyEvent.getAction() == KeyEvent.ACTION_DOWN && i == KeyEvent.KEYCODE_BACK){ //Toast.makeText(getActivity(), "按了返回键", Toast.LENGTH_SHORT).show(); return true; } Utils.Log("按了返回键"); return false; } }); }
标签:getView,Toast,onResume,KeyEvent,Fragment,public,Override,Android,监听 来源: https://www.cnblogs.com/pxjbk/p/11427953.html