有一个默认的返回键(器件)监听器在Android的?监听器、有一个、器件、Android

2023-09-12 07:30:29 作者:容顏未老,心已蒼涼

我有两个活动A和B,当我点击一个该遗嘱的按钮显示B.当我点击B中它备份到答:我已经设置完成()方法后overridePendingTransition方法的按钮。它工作正常。但如果目前的活动是B.在那个时候我单击默认后退按钮的设备。它显示向左转移的权利,显示的活性。

我怎么能监听设备默认返回键?

编辑:

  Log.v(TAG,回pressed);
完();
overridePendingTransition(R.anim.slide_top_to_bottom,R.anim.hold);
 

解决方案

  @覆盖
公共布尔的onkeydown(INT键code,KeyEvent的事件){
    如果(键code == KeyEvent.KEY code_BACK和放大器;&安培; event.getRepeatCount()== 0){
        //做一些事情就回来了。
        返回true;
    }

    返回super.onKeyDown(键code,事件);
}
 

下面这个链接是关于如何处理返回键事件,写的Andr​​oid开发自己的详细说明:

Using返回键

不用外设就让手机秒变蓝牙键鼠 Android 9.0 或许能帮你实现

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?

EDIT:

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);
}

The following link is a detailed explanation on how to handle back key events, written by the Android developers themselves:

Using the back key