How to clear focus in fragment with single focusable view?

android, android-fragments, focus

Solution

I've used this trick: set up another view as `android:focusable` (and also `android:focusableInTouchMode`) and call `requestFocus()` on it.

You can use a dummy view for this, such as a FrameLayout tucked somewhere.

Problem

I have a fragment with a single focusable element (a TextView). The problem I have is that I can't force the element to lose its focus appearance (e.g. color) once it has gained it focus, even if navigating away from the fragment -another element in a separate fragment has the focus, but both (TextView instances) appear to be focused. I've tried calling `getActivity().getCurrentFocus().clearFocus()` on the fragment without luck. My understanding is that given it is the only focusable element Android will reassign focus to it, but not sure. Is there any way to accomplish this?

Original source