Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tom5079/FloatingSearchView
Complete Kotlin port of arimorty/FloatingSearchView
https://github.com/tom5079/FloatingSearchView
Last synced: 3 months ago
JSON representation
Complete Kotlin port of arimorty/FloatingSearchView
- Host: GitHub
- URL: https://github.com/tom5079/FloatingSearchView
- Owner: tom5079
- License: apache-2.0
- Created: 2020-09-15T11:07:50.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-08T09:06:05.000Z (over 2 years ago)
- Last Synced: 2024-07-11T18:14:51.008Z (4 months ago)
- Language: Kotlin
- Size: 431 KB
- Stars: 17
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - tom5079/FloatingSearchView - Complete Kotlin port of arimorty/FloatingSearchView (Kotlin)
README
Floating Search View
=============
## Complete Kotlin/AndroidX port of [arimorty/FloatingSearchView](https://github.com/arimorty/floatingsearchview)An implementation of a floating search box with search suggestions, also called persistent search bar.
![Alt text](https://github.com/arimorty/floatingsearchview/blob/master/images/150696.gif)
![Alt text](https://github.com/arimorty/floatingsearchview/blob/master/images/1506tq.gif)
![Alt text](https://github.com/arimorty/floatingsearchview/blob/master/images/1508kn.gif)...
Usage
-----1. In your dependencies, add
```
implementation 'xyz.quaver:floatingsearchview:1.2.0-rc2'
```
2. Add a FloatingSearchView to your view hierarchy, and make sure that it takes
up the full width and height of the screen
3. Listen to query changes and provide suggestion items that implement SearchSuggestion**Example:**
```xml
```
### Kotlin
```kotlin
binding.searchView.onQueryChangeListener = { oldQuery, newQuery -> {
//get suggestions based on newQuery
//pass them on to the search view
binding.searchView.swapSuggestions(newSuggestions);
}
```### Java
```java
mSearchView.setOnQueryChangeListener((oldQuery, newQuery) -> {
//get suggestions based on newQuery//pass them on to the search view
mSearchView.swapSuggestions(newSuggestions);return Unit.INSTANCE;
});
```**Left action mode:**
The left action can be configured as follows:
Add
```xml
app:leftActionMode="[insert one of the options from table below]"
```
showHamburger
showSearch
showHome
noLeftAction
Listen to *hamburger* button clicks:
```kotlin
binding.searchView.onMenuClickListener = object: FloatingSearchView.OnLeftMenuClickListener {
...
}
```To quickly connect your **NavigationDrawer** to the *hamburger* button:
```kotlin
binding.menuView.attachNavigationDrawerToMenuButton(mDrawerLayout);
```Listen to home (back arrow) button clicks:
```kotlin
binding.menuView.setOnHomeActionClickListener(
new FloatingSearchView.OnHomeActionClickListener() { ... });
```
**Configure menu items:**
![Alt text](https://github.com/arimorty/floatingsearchview/blob/master/images/150sg9.gif)
Add a menu resource
```xml
app:menu="@menu/menu_main"
```In the menu resource, set items' ```app:showAsAction="[insert one of the options described in the table below]"```
never
Puts the menu item in the overflow options popup
ifRoom
Shows an action icon for the menu if the following conditions are met:
1. The search is not focused.
2. There is enough room for it.
always
Shows an action icon for the menu if there is room, regardless of whether the search is focused or not.
Listen for item selections
```kotlin
binding.searchView.onMenuItemClickListener = { item ->}
```**Configure suggestion item:**
First, implement [SearchSuggestion](https://github.com/tom5079/floatingsearchview/blob/master/library/src/main/kotlin/xyz/quaver/floatingsearchview/suggestions/model/SearchSuggestion.java)
*Optional*:
Set a callback for when a given suggestion is bound to the suggestion list.
For the history icons to show, you would need to implement this. Refer to the sample app for an [example implementation](https://github.com/tom5079/FloatingSearchView/blob/master/app/src/main/java/xyz/quaver/floatingsearchview/sample/fragment/ScrollingSearchExampleFragment.java#L222).
```
binding.searchView.onBindSuggestionCallback = { binding, item, itemPosition ->
// suggestionView = binding.root, leftIcon = binding.leftIcon, textView = binding.body
//here you can set some attributes for the suggestion's left icon and text. For example,
//you can choose your favorite image-loading library for setting the left icon's image.
});
```**Styling:**
Available styling:
```xml
<item name="backgroundColor"></item>
<item name="viewSearchInputTextColor"></item>
<item name="viewSuggestionItemTextColor"></item>
<item name="hintTextColor"></item>
<item name="dividerColor"></item>
<item name="clearBtnColor"></item>
<item name="leftActionColor"></item>
<item name="menuItemIconColor"></item>
<item name="suggestionRightIconColor"></item>
<item name="actionMenuOverflowColor"></item>
````backgroundColor` uses `colorSurface` value defined in Theme.
To change `backgroundColor` according to Light/Dark Theme, define `colorSurface` or use `Theme.Material`/`Theme.MaterialComponents` as a parent.
Otherwise, `backgroundColor` defaults to White.License
=======
tom5079/FloatingSearchView was ported from arimorty/FloatingSearchViewCopyright 2015 Ari C.
Copyright 2020 tom5079Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.