問題描述
我有兩個活動 A 和 B.當我單擊 A 中將顯示 B 的按鈕時.當我單擊 B 中的按鈕時,它返回到 A.我在 finish() 方法之后設置了 overridePendingTransition 方法.它工作正常.但如果當前的活動是 B.那時我點擊設備中的默認后退按鈕.它顯示從右到左的過渡以顯示 Activity A.
I am having two activities A and B. when i click the button in A that will shows B. when i click the Button in B it backs to A. i had set the overridePendingTransition method after the finish() method. it works properly. but in case the current Activity is B. on that time i click the default back button in the device. it shows the right to left transition to show the Activity A.
如何在設備上收聽默認返回鍵?
How i can listen that Default back key on device?
Log.v(TAG, "back pressed");
finish();
overridePendingTransition(R.anim.slide_top_to_bottom, R.anim.hold);
推薦答案
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
return true;
}
return super.onKeyDown(keyCode, event);
}
以下鏈接是Android開發者自己編寫的關于如何處理返回鍵事件的詳細說明:
The following link is a detailed explanation on how to handle back key events, written by the Android developers themselves:
使用返回鍵
這篇關于android中是否有默認的后退鍵(在設備上)偵聽器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!