Индивидуальный SearchView - PullRequest
       6

Индивидуальный SearchView

0 голосов
/ 08 февраля 2019

Я хочу отобразить вид поиска, как показано ниже enter image description here

и в фокусе это будет выглядеть так: enter image description here

Теперь моя проблема в том, что я не могу найти, как настроить макет SearchView, и я создаю поисковое представление в макете вместо меню, как показано в коде ниже

toolbar_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>

Как я могу достичь дизайна, описанного выше, я хочу обновить свою реализацию, чтобы использовать меню, но я не знаю, как.

...