ClearFocus 将焦点设置在 LinearLayout 中的第一个视图上
ClearFocus sets focus on the first view in LinearLayout
当调用 LinearLayout 上的 clearFocus() 时,它会将焦点设置在 Linearlayout 中的第一个视图上。我正在阅读 android 查看文档,上面写着
Note: When not in touch-mode, the framework will try to give focus to the first focusable View from the top after focus is cleared. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view.
enter link description here
因此,我在调用 clearFocus 之前检查了 LinearLayout 上的 IsInTouchMode,但 IsInTouchMode 为真。
我想知道是什么影响了这种行为。
Use android:descendantFocusability="beforeDescendants" so that focus will be first on parent layout and then on their child/s.
像这样:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical" />
让我知道它是否有效。
当调用 LinearLayout 上的 clearFocus() 时,它会将焦点设置在 Linearlayout 中的第一个视图上。我正在阅读 android 查看文档,上面写着
Note: When not in touch-mode, the framework will try to give focus to the first focusable View from the top after focus is cleared. Hence, if this View is the first from the top that can take focus, then all callbacks related to clearing focus will be invoked after which the framework will give focus to this view. enter link description here
因此,我在调用 clearFocus 之前检查了 LinearLayout 上的 IsInTouchMode,但 IsInTouchMode 为真。
我想知道是什么影响了这种行为。
Use android:descendantFocusability="beforeDescendants" so that focus will be first on parent layout and then on their child/s.
像这样:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical" />
让我知道它是否有效。