@@ -4032,8 +4032,9 @@ public boolean requestRectangleOnScreen(Rect rectangle, boolean immediate) {
40324032 * <p>
40334033 * <strong>Note:</strong> When a View clears focus the framework is trying
40344034 * to give focus to the first focusable View from the top. Hence, if this
4035- * View is the first from the top that can take focus, then its focus will
4036- * not be cleared nor will the focus change callback be invoked.
4035+ * View is the first from the top that can take focus, then all callbacks
4036+ * related to clearing focus will be invoked after wich the framework will
4037+ * give focus to this view.
40374038 * </p>
40384039 */
40394040 public void clearFocus() {
@@ -4050,25 +4051,22 @@ public void clearFocus() {
40504051
40514052 onFocusChanged(false, 0, null);
40524053 refreshDrawableState();
4054+
4055+ ensureInputFocusOnFirstFocusable();
40534056 }
40544057 }
40554058
4056- /**
4057- * Called to clear the focus of a view that is about to be removed.
4058- * Doesn't call clearChildFocus, which prevents this view from taking
4059- * focus again before it has been removed from the parent
4060- */
4061- void clearFocusForRemoval() {
4062- if ((mPrivateFlags & FOCUSED) != 0) {
4063- mPrivateFlags &= ~FOCUSED;
4064-
4065- onFocusChanged(false, 0, null);
4066- refreshDrawableState();
4067-
4068- // The view cleared focus and invoked the callbacks, so now is the
4069- // time to give focus to the the first focusable from the top to
4070- // ensure that the gain focus is announced after clear focus.
4071- getRootView().requestFocus(FOCUS_FORWARD);
4059+ void ensureInputFocusOnFirstFocusable() {
4060+ View root = getRootView();
4061+ if (root != null) {
4062+ // Find the first focusble from the top.
4063+ View next = root.focusSearch(FOCUS_FORWARD);
4064+ if (next != null) {
4065+ // Giving focus to the found focusable will not
4066+ // perform a search since we found a view that is
4067+ // guaranteed to be able to take focus.
4068+ next.requestFocus(FOCUS_FORWARD);
4069+ }
40724070 }
40734071 }
40744072
0 commit comments