55
66# Search
77
8- - Search component for Android
9- - Material You Design
10- - Styling
11- - Kotlin
8+ - Search component for Android
9+ - Material You Design
10+ - Styling
11+ - Kotlin
1212
1313![ Search] ( https://github.com/lapism/Search/blob/master/images/search.png )
1414
1515## Api
1616
17- - minSdkVersion = 21
18- - targetSdkVersion = 31
19- - Java = 1.8
20- - Kotlin = 1.8
17+ - minSdkVersion = 21
18+ - targetSdkVersion = 31
19+ - Java = 1.8
20+ - Kotlin = 1.8
2121
2222Add the dependency to your gradle file:
2323
@@ -42,45 +42,45 @@ dependencies {
4242### MaterialSearchBar
4343
4444``` java
45- val toolbar= binding. materialSearchBar. getToolbar()
45+ val toolbar = binding. materialSearchBar. getToolbar()
4646 setSupportActionBar(toolbar)
4747
48- binding. materialSearchBar. apply{
49- navigationIconCompat= NavigationIconCompat . SEARCH
50- setHint(getString(R . string. search))
51- setOnClickListener{
52- binding. materialSearchView. requestFocus()
53- }
54- setNavigationOnClickListener{
55- binding. materialSearchView. requestFocus()
56- }
48+ binding. materialSearchBar. apply {
49+ navigationIconCompat = NavigationIconCompat . SEARCH
50+ setHint(getString(R . string. search))
51+ setOnClickListener {
52+ binding. materialSearchView. requestFocus()
53+ }
54+ setNavigationOnClickListener {
55+ binding. materialSearchView. requestFocus()
56+ }
5757 }
5858```
5959
6060### MaterialSearchView
6161
6262``` java
63- binding. materialSearchView. apply{
64- addView(recyclerView)
65- navigationIconCompat= NavigationIconCompat . ARROW
66- setNavigationOnClickListener{
67- binding. materialSearchView. clearFocus()
68- }
69- setHint(getString(R . string. search))
70- setOnQueryTextListener(object: MaterialSearchView . OnQueryTextListener {
71- override fun onQueryTextChange(newText: CharSequence ){
72- adapter. filter(newText)
73- }
74-
75- override fun onQueryTextSubmit(query: CharSequence ){
76-
77- }
78- })
79- setOnFocusChangeListener(object: MaterialSearchView . OnFocusChangeListener {
80- override fun onFocusChange(hasFocus: Boolean ){
81-
82- }
83- })
63+ binding. materialSearchView. apply {
64+ addView(recyclerView)
65+ navigationIconCompat = NavigationIconCompat . ARROW
66+ setNavigationOnClickListener {
67+ binding. materialSearchView. clearFocus()
68+ }
69+ setHint(getString(R . string. search))
70+ setOnQueryTextListener(object : MaterialSearchView . OnQueryTextListener {
71+ override fun onQueryTextChange(newText: CharSequence ) {
72+ adapter. filter(newText)
73+ }
74+
75+ override fun onQueryTextSubmit(query: CharSequence ) {
76+
77+ }
78+ })
79+ setOnFocusChangeListener(object : MaterialSearchView . OnFocusChangeListener {
80+ override fun onFocusChange(hasFocus: Boolean ) {
81+
82+ }
83+ })
8484 }
8585```
8686
@@ -90,39 +90,51 @@ You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
9090
9191``` xml
9292<?xml version =" 1.0" encoding =" utf-8" ?>
93- <androidx .coordinatorlayout.widget.CoordinatorLayout
94- xmlns : android =" http://schemas.android.com/apk/res/android"
93+ <androidx .coordinatorlayout.widget.CoordinatorLayout xmlns : android =" http://schemas.android.com/apk/res/android"
9594 xmlns : app =" http://schemas.android.com/apk/res-auto"
96- xmlns : tools =" http://schemas.android.com/tools" android : layout_width =" match_parent"
97- android : layout_height =" match_parent" android : fitsSystemWindows =" false"
95+ xmlns : tools =" http://schemas.android.com/tools"
96+ android : layout_width =" match_parent"
97+ android : layout_height =" match_parent"
98+ android : fitsSystemWindows =" false"
9899 tools : context =" .activity.MainActivity" >
99100
100- <com .google.android.material.appbar.AppBarLayout android : layout_width =" match_parent"
101+ <com .google.android.material.appbar.AppBarLayout
102+ android : layout_width =" match_parent"
101103 android : layout_height =" wrap_content" >
102104
103105 <!-- Simple MaterialToolbar extension -->
104- <com .lapism.search.widget.MaterialSearchBar android : id =" @+id/material_search_bar"
105- android : layout_width =" match_parent" android : layout_height =" wrap_content"
106+ <com .lapism.search.widget.MaterialSearchBar
107+ android : id =" @+id/material_search_bar"
108+ android : layout_width =" match_parent"
109+ android : layout_height =" wrap_content"
106110 app : layout_scrollFlags =" scroll|enterAlways|snap" />
107111
108112 </com .google.android.material.appbar.AppBarLayout>
109113
110- <androidx .fragment.app.FragmentContainerView android : id =" @+id/nav_host_fragment"
114+ <androidx .fragment.app.FragmentContainerView
115+ android : id =" @+id/nav_host_fragment"
111116 android : name =" androidx.navigation.fragment.NavHostFragment"
112- android : layout_width =" match_parent" android : layout_height =" match_parent"
117+ android : layout_width =" match_parent"
118+ android : layout_height =" match_parent"
113119 app : defaultNavHost =" true"
114120
115121 app : layout_behavior =" @string/material_search_bar_scrolling_view_behavior"
116122
117123 app : navGraph =" @navigation/mobile_navigation" />
118124
119- <com .lapism.search.widget.MaterialSearchView android : id =" @+id/material_search_view"
120- android : layout_width =" match_parent" android : layout_height =" match_parent"
125+ <com .lapism.search.widget.MaterialSearchView
126+ android : id =" @+id/material_search_view"
127+ android : layout_width =" match_parent"
128+ android : layout_height =" match_parent"
121129 app : layout_anchor =" @id/material_search_bar" />
122130
123- <BottomNavigationView android : id =" @+id/bottom_navigation_view"
124- android : layout_width =" match_parent" android : layout_height =" wrap_content"
125- android : layout_gravity =" bottom" android : orientation =" vertical" app : layout_insetEdge =" bottom"
131+ <BottomNavigationView
132+ android : id =" @+id/bottom_navigation_view"
133+ android : layout_width =" match_parent"
134+ android : layout_height =" wrap_content"
135+ android : layout_gravity =" bottom"
136+ android : orientation =" vertical"
137+ app : layout_insetEdge =" bottom"
126138 app : menu =" @menu/menu_bottom_nav" />
127139
128140</androidx .coordinatorlayout.widget.CoordinatorLayout>
@@ -177,5 +189,4 @@ You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.
177189
178190## License
179191
180- This project is licensed under the Apache License 2.0 - see
181- the [ LICENSE] ( https://github.com/lapism/Search/blob/searchview/LICENSE ) file for details.
192+ This project is licensed under the Apache License 2.0 - see the [ LICENSE] ( https://github.com/lapism/Search/blob/searchview/LICENSE ) file for details.
0 commit comments