問(wèn)題描述
我有兩個(gè)活動(dòng) A 和 B.當(dāng)我單擊 A 中將顯示 B 的按鈕時(shí).當(dāng)我單擊 B 中的按鈕時(shí),它返回到 A.我在 finish() 方法之后設(shè)置了 overridePendingTransition 方法.它工作正常.但如果當(dāng)前的活動(dòng)是 B.那時(shí)我點(diǎn)擊設(shè)備中的默認(rèn)后退按鈕.它顯示從右到左的過(guò)渡以顯示 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.
如何在設(shè)備上收聽(tīng)默認(rèn)返回鍵?
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開(kāi)發(fā)者自己編寫(xiě)的關(guān)于如何處理返回鍵事件的詳細(xì)說(shuō)明:
The following link is a detailed explanation on how to handle back key events, written by the Android developers themselves:
使用返回鍵
這篇關(guān)于android中是否有默認(rèn)的后退鍵(在設(shè)備上)偵聽(tīng)器?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!