调用硬件后退按钮编程? [英] Call the hardware back button programatically?

查看:109
本文介绍了调用硬件后退按钮编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,一个可以覆盖在Android上的后退按钮功能,但我不知道是否有一种方法或什么我可以调用,将在功能上做同样的事情为pressing硬件按钮。

I know that one can overwrite the Back Button functionality in Android, but I was wondering if there was a method or anything I could call that would functionally do the same thing as pressing the hardware button.

推荐答案

您可以发送后退按钮preSS到系统中像这样

You can send the back button press to the system like this

this.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); 

或者你也可以覆盖后退按钮preSS和呼叫

Or you can override the back button press and call

finish();

您的活动。基本上做同样的事情作为一般的后退按钮。

on your Activity. That basically does the same thing as the generic back button.

这篇关于调用硬件后退按钮编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆