Skip to content

denchic45/SearchBar

Repository files navigation

SearchBar

Simple search bar in material design

Setup

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.denchic45:SearchBar:1.1'
}

Usage

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">  
  
  <com.denchic45.sample.SearchBar
    android:id="@+id/searchBar"  
    android:layout_width="match_parent"  
    android:layout_height="wrap_content"  
    app:layout_constraintEnd_toEndOf="parent"  
    app:layout_constraintStart_toStartOf="parent"
    app:searchBar_leftActionMode="search"
    app:layout_constraintTop_toTopOf="parent" />  
  
    Fragment or any container...
  
</androidx.constraintlayout.widget.ConstraintLayout>

Work with navigation drawer

Attach

searchBar.attachNavigationDrawer(drawerLayout)

Detach

searchBar.detachNavigationDrawer()

Listen changes

searchBar.setOnQueryTextListener(object : SearchBar.OnQueryTextListener() {  
    override fun onQueryTextChange(newText: String) {  
	//TODO
    }  
  
    override fun onQueryTextSubmit(query: String) {  
	//TODO
    }  
})

XML attributes

<declare-styleable name="SearchBar">  
  <attr name="searchBar_leftActionMode" format="integer">  
    <enum name="none" value="0" />  
    <enum name="menu" value="1" />  
    <enum name="search" value="2" />  
  </attr>
  <attr name="searchBar_leftIcon" format="reference" />  
  <attr name="searchBar_menu" format="reference" />  
  <attr name="expandable">  
    <enum name="enable" value="0" />  
    <enum name="alwaysCollapse" value="1" />  
    <enum name="alwaysExpand" value="2" />  
    <enum name="noAnimation" value="3" />  
  </attr>
  <attr name="menu" format="reference" />  
  <attr name="android:fontFamily" />  
  <attr name="android:hint" />  
  <attr name="android:letterSpacing" />  
  <attr name="android:layout_margin" />  
  <attr name="searchBar_content_layer" format="reference" />  
</declare-styleable>

About

Simple search bar in material design

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages