Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正要学习自己如何创建一个android应用程序。现在我正在寻找一种使用菜单硬件按钮的方法。我读到我必须创建一个 xml 文件,但我不明白我必须将它保存到哪里?获取菜单按钮的代码是什么?谁能给我一个简单的例子?
这个网站上有很多例子,你可以在你的活动上创建一个函数来捕捉事件:
public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { if (event.getAction() == KeyEvent.ACTION_UP) { //your code return true; } } return super.onKeyUp(keyCode, event); }