android 浮动搜索,一个浮动搜索框

收藏 0

另一个浮动搜索视图实现,也称为持久搜索:该实现完全支持菜单(包括子菜单),徽标和动画图标。支持RecyclerView,您可以提供自己的RecyclerView.Adapter,ItemDecorator或ItemAnimator。没有隐藏。

4ea6846891162c1c05023b47af004117.gif

Usage

Add a FloatingSearchView to your view hierarchy, make sure that it takes up the full width and height:

android:id="@+id/search"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingTop="16dp"

android:paddingRight="8dp"

android:paddingLeft="8dp"

android:background="#90000000"

android:hint="@string/hint"

app:logo="@drawable/logo"

app:fsv_menu="@menu/search"/>

Then, configure your instance and set your listeners to react accordingly:

mSuggestionsAdapter = new MySuggestionsAdapter(); // use a RecyclerView.Adapter

mSearchView.setAdapter(mSuggestionsAdapter);

...

mSearchView.setOnIconClickListener(...);

mSearchView.setOnSearchListener(...);

mSearchView.addTextChangedListener(...);

mSearchView.setOnSearchFocusChangedListener(...);

Look at the sample.

Menu

The implementation fully supports menu (and submenu):

...

app:fsv_menu="@menu/search"

/>

mSearchView.setOnMenuItemClickListener(...);

Menu items can be automatically hidden when the search view gets focus depending on the value of the MenuItem’s showAsAction:

// always shown

// will hide on focus

// will go into the overflow menu

Animated Icon

FloatingSearchView will automagically animate icons drawable, given they declare a progress property:

void setProgress(float)

float getProgress()

Other

Since the implementation tries to focus on core logic instead of business logic as much as possible, common features like “tap to clear”, “speech to text” or “loading progress” are voluntarily NOT built-in because they can be easily implemented using menu items as seen in the sample.

Styling

FloatingSearchView do not expose most of TextView’s XML attributes (textColor,textSize…). You can style them using theme attributes by applying app:theme for example:

First, create a dedicated theme, possibly heriting from your application theme:

@style/searchViewEditTextStyle

#c9c9c9

1dp

#696969

18sp

?android:attr/textColorPrimary

actionSearch

Then, apply your custom theme through app:theme:

...

app:theme="@style/CustomFloatingSearchViewTheme"

/>

Look at the sample.

Install

Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

...

maven { url "https://jitpack.io" }

}

}

Add the dependency:

dependencies {

compile 'com.github.renaudcerrato:FloatingSearchView:1.0.1'

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值