【发布时间】:2021-12-31 03:25:26
【问题描述】:
目前正在使用喷气背包导航并希望使用单个活动。但是,每当我从卡片详细信息返回搜索时,searchview 都会重新获得焦点,即使我在单击搜索后已移除焦点。见here。
我目前正在做的移除焦点是我的工具栏上方有一个虚拟视图
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/database_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
style="@style/Widget.MaterialComponents.Toolbar.Primary" />
<!-- Dummy view for receiving focus after SearchView clears focus -->
<View
android:id="@+id/focus_dummy_view"
android:focusableInTouchMode="true"
android:focusable="true"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintBottom_toTopOf="@id/database_toolbar" />
</com.google.android.material.appbar.MaterialToolbar>
在我执行搜索后,我会这样做
searchView.clearFocus()
binding.focusDummyView.requestFocus()
我目前的解决方法是在活动中托管详细信息,但我宁愿不这样做。我创建了一个新的project,但仍然看到此问题发生。
一些额外的上下文是,这仅在从 1.2.5 更新到 "androidx.fragment:fragment-ktx:1.4.0" 后发生。我在错误跟踪器中提出了这个问题,但他们还没有回复我。想知道是否有人知道解决方法?
【问题讨论】:
标签: android searchview android-jetpack-navigation