android - 自定义搜索视图
问题描述
现在我的问题是我找不到如何自定义 SearchView 布局,我正在布局而不是菜单中创建搜索视图,如下面的代码所示
工具栏_main.xml
<com.google.android.material.appbar.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.Toolbar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tbMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:padding="0dp"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetStartWithNavigation="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/toolbar_background">
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ibMenuButton"
style="@style/AppTheme.MenuButton"
android:src="@drawable/menu_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingStart="@dimen/ms_menu_padding_horizontal"
android:paddingEnd="@dimen/ms_menu_padding_horizontal"
android:contentDescription="@string/cd_menu_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.SearchView
android:id="@+id/tvSearch"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:iconifiedByDefault="false"
app:queryHint="@string/ms_hint_search"
app:searchIcon="@drawable/search_icon"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintWidth_max="@dimen/tt_main_search_max_width"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/ibMenuButton"
app:layout_constraintEnd_toStartOf="@id/ibHeartButton"
app:layout_constraintBottom_toBottomOf="parent">
</androidx.appcompat.widget.SearchView>
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ibHeartButton"
style="@style/AppTheme.MenuButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/heart_icon"
android:paddingStart="@dimen/ms_menu_padding_horizontal"
android:paddingEnd="@dimen/ms_menu_padding_horizontal"
android:contentDescription="@string/cd_menu_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/ibNotificationButton"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/ibNotificationButton"
style="@style/AppTheme.MenuButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/notification_icon"
android:paddingStart="@dimen/ms_menu_padding_horizontal"
android:paddingEnd="@dimen/ms_menu_padding_horizontal"
android:contentDescription="@string/cd_menu_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
我怎样才能实现上面的设计,我愿意修改我的实现以使用菜单,但我不知道如何。
解决方案
推荐阅读
- fuzzy-logic - 清晰数字的单个模糊隶属度值
- laravel - laravel 应用程序中未使用命名路由的应用程序基本 url
- java - 将 Excel VBA 代码集成到 Java 代码中,最终在 Excel 表格的单元格中创建从下拉列表中选择多个值的功能
- django - Django-REST:添加 API 以通过另一个字段获取实体的正确方法?
- unity3d - 如何为不同纵横比的屏幕设置 UI 位置动画?
- python - 如何在数据框中的特定单元格中填充颜色?
- security - 如何限制未经授权的调用图像调整服务?
- python - Python 将函数导入到另一个目录中的文件,该文件又从其自己的目录中导入另一个函数
- javascript - 如何在 iOS Swift 中使用 WKWebView 评估 javascript?
- java - 在 RecyclerView-AndroidX 中的项目之间添加不同的布局