This is Yet another floating search view library for android.
It is an easy to implement floating search view with customizations.
It Supports from Android SDK version 19 and above.
Requires androidx.
Step 1: Grab it
Gradle dependency:
Add the following to your project level build.gradle:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add this to your app build.gradle:
dependencies {
implementation 'com.github.vikramezhil:DroidFloatingSearchView:v2.0.1'
}
Alterbatively you can install it by adding the following to the section of your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add the following to the section of your pom.xml:
<dependency>
<groupId>com.github.vikramezhil</groupId>
<artifactId>DroidFloatingSearchView</artifactId>
<version>v2.0.1</version>
</dependency>
Step 2: Add to Layout
In your layout file add Droid Floating Search View,
<github.com.vikramezhil.dfsv.Dfsv
android:id="@+id/dfsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dfsvBgColor="@android:color/holo_purple"
app:dfsvOverlayBgColor="@android:color/holo_purple"
app:dfsvTextColor="@android:color/white"
app:dfsvHintTextColor="@android:color/white"
app:dfsvDividerColor="@android:color/white"
app:dfsvIconsColor="@android:color/white"
app:dfsvHintText="@string/search_hint"
app:dfsvCornerRadius="10"
app:dfsvElevation="5"
app:dfsvCloseSearchOnOverlayTouch="false"
app:dfsvContinuousSearch="false"
app:dfsvSuggestions="@array/suggestions"/>
Step 3: Reference and Use
In your class file, initialize Droid Floating Search View using the ID specified in your layout file
DroidFSView dfsView = findViewById(R.id.dfsView);
Set and implement the Droid Floating Search View listener methods
dfsView.setOnDroidFSViewListener(new OnDroidFSViewListener() {
@Override
public void onHasFocus() {
Log.i(TAG, "Has focus");
}
@Override
public void onLostFocus() {
Log.i(TAG, "Lost focus");
}
@Override
public void onSearchTextChanged(String oldQuery, String newQuery) {
Log.i(TAG, "Old query = " + oldQuery + ", New Query = " + newQuery);
}
@Override
public void onSearchText(String searchQuery) {
Log.i(TAG, "Query to search = " + searchQuery);
}
@Override
public void onActionItemClicked() {
Log.i(TAG, "Action item clicked");
}
});
Full Example
Here is a full example:
(a). activity_dfsv.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<github.com.vikramezhil.dfsv.Dfsv
android:id="@+id/dfsView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dfsvBgColor="@android:color/holo_purple"
app:dfsvOverlayBgColor="@android:color/holo_purple"
app:dfsvTextColor="@android:color/white"
app:dfsvHintTextColor="@android:color/white"
app:dfsvDividerColor="@android:color/white"
app:dfsvIconsColor="@android:color/white"
app:dfsvHintText="@string/search_hint"
app:dfsvCornerRadius="10"
app:dfsvElevation="5"
app:dfsvCloseSearchOnOverlayTouch="false"
app:dfsvContinuousSearch="false"
app:dfsvSuggestions="@array/suggestions"/>
</RelativeLayout>
(a). ActivityDfsv.java
Droid Floating Search View Activity
package github.com.vikramezhil.dfsvexample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import github.com.vikramezhil.dfsv.Dfsv;
import github.com.vikramezhil.dfsv.OnDfsvListener;
public class ActivityDfsv extends Activity {
private final String TAG = "ActivityDFSV";
private Dfsv dfsView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dfsv);
dfsView = findViewById(R.id.dfsView);
dfsView.setOnDfsvListener(new OnDfsvListener() {
@Override
public void onHasFocus() {
Log.i(TAG, "Has focus");
}
@Override
public void onLostFocus() {
Log.i(TAG, "Lost focus");
}
@Override
public void onSearchTextChanged(String oldQuery, String newQuery) {
Log.i(TAG, "Old query = " + oldQuery + ", New Query = " + newQuery);
}
@Override
public void onSearchText(String searchQuery) {
Log.i(TAG, "Query to search = " + searchQuery);
}
@Override
public void onActionItemClicked() {
Log.i(TAG, "Action item clicked");
}
});
}
@Override
protected void onPause() {
super.onPause();
dfsView.closeSearchView();
}
}
Reference
Read more here.
Download code here.
Follow code author here.