Processing method of Android videoview seizing focus
Problem Description:
Android set top box application: the main activity of the application has only two controls, a videoview and a button. The video frame is set without focus, and the key has focus.
When entering the application for the first time, the focus is normal and focuses on the button; However, when you click the button to jump to the next activity and return, the focus is focused on the videoview, and the focus is forcibly set in the code:
Button.requestFocus();
Invalid. The phenomenon is that when the video is loaded, the focus is at the button, but when the video is loaded and started playing, the whole activity loses focus. A few seconds later, the focus goes to the videoview.
Cause analysis:
After checking the source code of videoview, it is found that the reason is initialization:
It's clear from here. This explains why Android: focusable = "false" is set in XML and videoview can still get the focus. It also explains why button gets the focus and is preempted by videoview when the video is loaded.
resolvent:
If you understand the problem, you can solve it. Because it only solves the focus problem, you don't need to customize the videoview. You just need to rewrite the onresume() method:
Summary:
Be sure to look at the source code!
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.