Set movement method to the focusable text

The keyboard navigation should work for focusable text, thus
set ArrowKeyMovementMethod to the focusable TextView.

Bug: 244260144
Test: Manually done with demo app
Change-Id: I0b1e046b84641a40cb801e107980504dccd31f8a
This commit is contained in:
Seigo Nonaka
2022-10-09 13:58:06 +09:00
parent 862f455db7
commit 8b5927e5e2

View File

@@ -2438,7 +2438,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* Subclasses override this to specify a default movement method.
*/
protected MovementMethod getDefaultMovementMethod() {
return null;
if (isFocusable() || isFocusableInTouchMode()) {
return ArrowKeyMovementMethod.getInstance();
} else {
return null;
}
}
/**
@@ -2653,9 +2657,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
/**
* Gets the {@link android.text.method.MovementMethod} being used for this TextView,
* which provides positioning, scrolling, and text selection functionality.
* This will frequently be null for non-EditText TextViews.
* By default, this returns an instance of {@link android.text.method.ArrowKeyMovementMethod}
* if this View is focusable or focusable in touch mode.
*
* @return the movement method being used for this TextView.
* @see android.text.method.MovementMethod
* @see android.text.method.ArrowKeyMovementMethod
*/
public final MovementMethod getMovementMethod() {
return mMovement;