註銷應用程序時如何在android中禁用後退按鈕? android
我正在使用............. app
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_BACK) Toast.makeText(getApplicationContext(), "back press", Toast.LENGTH_LONG).show(); return false; // Disable back button.............. }
若是您正在使用FragmentActivity
。 而後像這樣 ide
首先在您的Fragment
調用This。 spa
public void callParentMethod(){ getActivity().onBackPressed(); }
而後在父FragmentActivity
類的旁邊調用onBackPressed
方法。 code
@Override public void onBackPressed() { //super.onBackPressed(); //create a dialog to ask yes no question whether or not the user wants to exit ... }
只需重寫onBackPressed()方法。 get
@Override public void onBackPressed() { }
您能夠經過如下簡單方法進行操做:不要調用super.onBackPressed() it
@Override public void onBackPressed() { // super.onBackPressed(); // Not calling **super**, disables back button in current screen. }
您只須要覆蓋後退按鈕的方法便可。 您能夠根據須要將方法保留爲空,以便在按「後退」按鈕時不進行任何操做。 請看下面的代碼: io
@Override public void onBackPressed() { // Your Code Here. Leave empty if you want nothing to happen on back press. }