Android 自定义搜索视图

Android 自定义搜索视图,android,searchview,Android,Searchview,我想显示如下所示的搜索视图 当聚焦时,它会像这样 现在我的问题是,我找不到如何自定义SearchView布局,我正在布局中创建SearchView,而不是在下面的代码所示的菜单中创建SearchView toolbar\u main.xml <com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ap

我想显示如下所示的搜索视图

当聚焦时,它会像这样

现在我的问题是,我找不到如何自定义SearchView布局,我正在布局中创建SearchView,而不是在下面的代码所示的菜单中创建SearchView

toolbar\u 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>

我如何实现上面的设计,我愿意修改我的实现以使用菜单,但我不知道如何实现