因此,当我遇到错误“无法解析类 SearchView”时,我尝试在我的应用程序中包含搜索栏。谷歌没有帮助所以我来到这里。这是我的代码:
<SearchView
android:layout_width="410dp"
android:layout_height="44dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="2dp"
app:layout_constraintBottom_toTopOf="@+id/grid_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)
xml 的其余部分已正确完成,并且我直接从 android 获取了小部件,所以这让我感到困惑。感谢所有帮助,谢谢。
小智 13
也许您需要为android组件指定SearchView的完整路径。
<android.widget.SearchView
android:layout_width="410dp"
android:layout_height="44dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="2dp"
app:layout_constraintBottom_toTopOf="@+id/grid_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)
尽管解决了问题,但 OP 没有回答,因此将此作为答案发布。
如果您的项目正在使用,androidx
则需要在布局中使用组件(在设计调色板中androidx
放置项目时,这还不是默认设置)。SearchView
<androidx.appcompat.widget.SearchView
android:layout_width="410dp"
android:layout_height="44dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="2dp"
app:layout_constraintBottom_toTopOf="@+id/grid_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6593 次 |
最近记录: |