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 设备上的一个真正的按钮。目前我正在用dispatchKeyEvent因为onKeyUp并且onKeyDown没有工作来覆盖音量键。在整个应用程序中,都会弹出一些小对话框或上下文菜单。问题是当它们集中注意力时,我会失去对音量按钮的控制,它会调整主音量,而不是像我的按钮一样。有没有办法完全接管音量按钮?任何帮助,将不胜感激。
dispatchKeyEvent
onKeyUp
onKeyDown
-mlove
您必须实现一个类型的侦听器DialogInterface.OnKeyListener并将其设置在您的对话框中setOnKeyListener以捕获音量键。
DialogInterface.OnKeyListener
setOnKeyListener