arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

How to set a rightIcon for a search suggestion item? I only found leftIcon #257

Closed AnotherJack closed 5 years ago

joxad commented 7 years ago

you can create in your project layout an new item that is called the same name that the one used in the libs. THis way, it will override the layout provided by your implementation.

example for me : search_suggestion_item.xml

`<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/suggestion_item_background" android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/left_icon"
        android:layout_width="@dimen/square_button_size"
        android:layout_height="@dimen/square_button_size"
        android:layout_gravity="center"
        android:layout_marginStart="@dimen/search_bar_left_icon_left_margin"
        android:alpha="1"
        android:padding="@dimen/square_button_padding"
        android:visibility="gone" />

    <TextView
        android:id="@+id/body"
        style="@style/TextViewGreyLightNormal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/margin_half_medium"
        android:contentDescription=""
        android:drawableEnd="@drawable/ic_chevron_right_grey_extra_light_24dp"
        android:gravity="center_vertical"
        android:paddingStart="@dimen/margin_medium"
        tools:text="search content" />

    <ImageView
        android:id="@+id/right_icon"
        android:layout_width="@dimen/square_button_size"
        android:layout_height="@dimen/square_button_size"
        android:layout_gravity="center"
        android:layout_marginEnd="@dimen/search_bar_right_icon_right_margin"
        android:alpha="1"
        android:background="@drawable/oval_btn_selector"
        android:padding="@dimen/square_button_padding"
        android:rotation="45"
        android:src="@drawable/ic_arrow_back_black_24dp"
        android:visibility="gone" />

</LinearLayout>

<View
    android:id="@+id/view"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/colorGrey" />

`

ahmedkamalio commented 5 years ago

Don't reinvent the wheel

SearchSuggestionsAdapter.OnBindSuggestionCallback { view, leftIcon, textView, item, _ ->
  val rightIcon = view?.findViewById<ImageView>(R.id.right_icon) // you have access to it here...
}