feat: replace old searchbar implementation with official material3

This commit is contained in:
antonio 2023-06-24 11:15:04 +02:00
parent d7c5be834e
commit 3b80725673
5 changed files with 192 additions and 105 deletions

View file

@ -1,54 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent">
<com.paulrybitskyi.persistentsearchview.PersistentSearchView
android:id="@+id/persistentSearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
app:areSuggestionsDisabled="false"
app:cardBackgroundColor="?attr/colorSurface"
app:cardCornerRadius="0dp"
app:cardElevation="0dp"
app:clearInputButtonDrawable="@drawable/ic_close"
app:dividerColor="@color/dividerColor"
app:isClearInputButtonEnabled="true"
app:isDismissableOnTouchOutside="true"
app:isProgressBarEnabled="true"
app:isVoiceInputButtonEnabled="false"
app:leftButtonDrawable="@drawable/ic_search"
app:progressBarColor="?attr/colorOnSurface"
app:queryInputBarIconColor="@color/searchPlaceholderColor"
app:queryInputCursorColor="?attr/colorOnSurface"
app:queryInputHint="@string/search_hint"
app:queryInputHintColor="@color/searchPlaceholderColor"
app:queryInputTextColor="@color/searchPlaceholderColor"
app:shouldDimBehind="false"
app:suggestionRecentSearchIconColor="@color/searchColor"
app:suggestionSearchSuggestionIconColor="@color/searchColor"
app:suggestionSelectedTextColor="?attr/colorPrimary"
app:suggestionTextColor="@color/searchColor"
app:suggestionIconColor="@color/searchColor" />
<View
android:id="@+id/search_bar_divider"
android:layout_width="match_parent"
android:layout_height="0.75dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:layout_below="@+id/persistentSearchView"
android:background="?attr/colorSurfaceVariant" />
<androidx.core.widget.NestedScrollView
android:id="@+id/search_result_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/search_bar_divider">
android:layout_height="match_parent"
app:layout_behavior="@string/searchbar_scrolling_view_behavior">
<!-- Search result -->
<LinearLayout
@ -56,6 +16,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="64dp"
android:paddingBottom="@dimen/global_padding_bottom">
<!-- Artist -->
@ -150,4 +111,39 @@
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.search.SearchBar
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/search_hint">
</com.google.android.material.search.SearchBar>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.search.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/search_hint"
app:layout_anchor="@id/search_bar">
<!-- Content goes here (ScrollView, RecyclerView, etc.). -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:paddingBottom="@dimen/global_padding_bottom">
<LinearLayout
android:id="@+id/search_view_suggestion_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView>
</com.google.android.material.search.SearchView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp">
<ImageView
android:id="@+id/search_suggestion_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_history"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/search_suggestion_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginHorizontal="12dp"
android:text="@string/label_placeholder"
android:textAppearance="?attr/textAppearanceBody2"
app:layout_constraintBottom_toBottomOf="@id/search_suggestion_icon"
app:layout_constraintEnd_toStartOf="@id/search_suggestion_delete_icon"
app:layout_constraintStart_toEndOf="@id/search_suggestion_icon"
app:layout_constraintTop_toTopOf="@id/search_suggestion_icon" />
<ImageView
android:id="@+id/search_suggestion_delete_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/ic_close"
app:layout_constraintBottom_toBottomOf="@id/search_suggestion_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/search_suggestion_title"
app:layout_constraintTop_toTopOf="@id/search_suggestion_icon"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>