I tried a few things to resolve this problem, and it took a while to find what seems to be the best solution. First, I tried setting android:focusable="false" on pretty much everything in my layout XML files. This seemed to have no effect whatsoever, and left me with no other clear options.
There were a few other hacks I tried. I tried manually calling view.setFocusable(false); on the top-level controls, and although ugly and tedious, this almost worked. The only problem was with the ZoomControls widget, which is a compound widget comprising two buttons. These child buttons would end up getting highlighted as if focused, but never really kept focus. The trackball panning feature worked, but one of the buttons would end up permanently highlighted.
I eventually decided to look for a way to walk all the views in a tree, to make them all unfocusable as an act of desperation. Fortunately, I encountered the setDescendantFocusability method in the ViewGroup class. I tried setting this to FOCUS_BLOCK_DESCENDANTS on my top-level view, and this did a great job of preventing any controls from highlighting, but also blocked all the trackball events. I tried requesting focus explicitly for the top-level view, but this had no effect. Finally, I explicitly set the view to be focusable, and that fixed the feature!
In short:
public SandView(Context context, AttributeSet attrs) {
super(context, attrs);
setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS);
setFocusable(true);
requestFocus();
}
No comments:
Post a Comment