触发按钮点击在Android的后退按钮功能 [英] Trigger back-button functionality on button click in Android

查看:104
本文介绍了触发按钮点击在Android的后退按钮功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们有后退按钮在Android的移动我们回到了previous形式,但我的团队负责人要求把上的按钮单击后退按钮功能

I know we have back button in android to move us back on the previous form, but my team leader asked to put a back button functionality on button click

我怎样才能做到这一点?

How can I do this?

推荐答案

您应该使用完成()时,为了去到$用户点击该按钮p $ pvious活动。

You should use finish() when the user clicks on the button in order to go to the previous activity.

Button backButton = (Button)this.findViewById(R.id.back);
backButton.setOnClickListener(new OnClickListener() {
  @Override
  public void onClick(View v) {
    finish();
  }
});

另外,如果你真的需要,你可以尝试触发自己的返回键preSS:

Alternatively, if you really need to, you can try to trigger your own back key press:

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

执行这两个。

Execute both of these.

这篇关于触发按钮点击在Android的后退按钮功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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