“返回”异常时的按钮用过的

发布于 2024-12-08 15:58:29 字数 637 浏览 0 评论 0原文

当我接近完成我的项目时,我遇到了一个非常奇怪的效果。我将该行引入

<uses-sdk android:minSdkVersion="8" />

到清单中,并在模拟器和手机 (HTC Desire) 中重新运行该项目。我注意到“后退”按钮在程序的许多区域都不起作用。当我将代码放入调试中时,onKeyDown 侦听器正常触发[并将 ok 传递给 super.onKeyDown(..)],而 onBackPressed code> 监听器根本没有触发。

当我从清单中删除 uses-sdk 条目时,一切都恢复正常。谁能解释一下,因为我真的需要使用 min-sdk 语句。

更新: 我已经尝试了 min-sdk="1" (默认值),效果是一样的。然后,我删除了 min-sdk 值并使用 target-sdk 值代替,结果完全相同,即后退按钮在所有地方都不起作用。只需删除标签 就可以完全修复效果,但给我带来了在部署之前需要声明最小 sdk 值的问题。请帮忙,某人,任何人...

I have encountered a very strange effect as I get near to finishing my project. I introduced the line

<uses-sdk android:minSdkVersion="8" />

into the manifest and re-ran the project in both the emulator and a phone (HTC Desire). I noticed that the "back" button wasn't operating in a number of areas of the program. When I put the code into debug, the onKeyDown listener was firing OK [and handed off ok to super.onKeyDown(..)] whereas the onBackPressed listener wasn't firing at all.

When I removed the uses-sdk entry from the manifest all returned to normal. Can anyone explain please because I really need to use the min-sdk statement.

Update:
I have experimented right down to min-sdk="1" (the default value) and the effect is the same. I then removed the min-sdk value and used the target-sdk value instead with EXACTLY THE SAME consequences i.e. the back button won't work in all places. Simply removing the tag <uses-sdk .... /> completely fixes the effect but leaves me with the problem of needing to declare a minimum sdk value before I deploy. Please help, someone, anybody...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春有你 2024-12-15 15:58:29

也许我们遇到了同样的问题。
我使用这种方式来模拟软后退按钮,但是当“min-sdk”时添加后,按钮不起作用。似乎“dispatchKeyEvent”和“min-sdk”有冲突。我用“onBackPressed”代替,它对我来说效果很好。

public class BackButtonClickListener implements View.OnClickListener {
    public void onClick(View v) {
        Activity host = (Activity) v.getRootView().getContext();
        host.onBackPressed();
    }
} 
Button back = (Button) findViewById(R.id.your_button_id);
back.setOnClickListener(new BackButtonClickListener());

Maybe we met the same problem.
I use this way to simulate a soft back button, but when "min-sdk" is added, the button doesn't work. It seems like "dispatchKeyEvent" and "min-sdk" are in conflict. I used "onBackPressed" instead, it works fine for me.

public class BackButtonClickListener implements View.OnClickListener {
    public void onClick(View v) {
        Activity host = (Activity) v.getRootView().getContext();
        host.onBackPressed();
    }
} 
Button back = (Button) findViewById(R.id.your_button_id);
back.setOnClickListener(new BackButtonClickListener());
沧笙踏歌 2024-12-15 15:58:29

为什么不使用onKeyDown?

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK) {
    // do some stuff
    return true;
  }
  return super.onKeyDown(keyCode, event);
}

Why not use onKeyDown?

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_BACK) {
    // do some stuff
    return true;
  }
  return super.onKeyDown(keyCode, event);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文