Android的后退按钮和MediaController [英] Android back button and MediaController
问题描述
我知道如何利用后退按钮的控制权。我有一个 VideoView
嵌入在的FrameLayout
。我的问题是当视频弹出,视频控件是present几秒钟。点击Back按钮,而他们看到隐藏的视频控件。有没有办法忽略的功能,做下一个动作后面,如果视频控件不可见?
I know how to take control of the back button. I have a VideoView
embedded in a FrameLayout
. My question is when the video pops up, the video controls are present for a few seconds. Hitting the back button while they are visible hides the video controls. Is there a way to ignore that function and do the next back action as if the video controls weren't visible?
我想问的原因是,如果我真的想回去,我必须打的返回按钮两次;一旦隐藏控件和第二实际回去
The reason I ask is if I really do want to go back, I must hit the back button twice; once to hide the controls and second to actually go back
推荐答案
根据源$ C $ C,这应该工作:
Based on the source code, this should work:
- 扩展
的MediaController
(对于这个答案的目的,把它叫做RonnieMediaController
) - 覆盖
dispatchKeyEvent()
在RonnieMediaController
- 在链接到超,检查
KeyEvent.KEY code_BACK
,并且如果遇到,告诉你的活动完成( )
- 使用
RonnieMediaController
,而不是的MediaController
与你的VideoView
- Extend
MediaController
(for the purposes of this answer, call itRonnieMediaController
) - Override
dispatchKeyEvent()
inRonnieMediaController
- Before chaining to the superclass, check for
KeyEvent.KEYCODE_BACK
, and if that is encountered, tell your activity tofinish()
- Use
RonnieMediaController
instead ofMediaController
with yourVideoView
就个人而言,我只希望息事宁人,与此更改用户不能使 RonnieMediaController
消失的需求。
Personally, I'd just leave it alone, as with this change your user cannot make a RonnieMediaController
disappear on demand.
这篇关于Android的后退按钮和MediaController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!