动画是模仿一个app( package names viewe) 的搜索控件
网上找了好久 没找到,只能自己造轮子
如何使用?
implementation 'com.gitee.Pino_W:search-view:v1.0.3'
布局 ,这里有细节 SearchView要配合FrameLayout使用,SearchView要放在最后面,层级最高
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.uni.search_view.SearchView
android:id="@+id/sv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startMode="left"
app:aotuOpen="true"
/>
<com.uni.search_view.SearchView
android:id="@+id/sv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:startMode="right"
android:visibility="gone"
/>
</FrameLayout>
代码实现
public class SearchActivity extends AppCompatActivity {
SearchView searchView;
SearchView searchView2;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
searchView=findViewById(R.id.sv1);
searchView2=findViewById(R.id.sv2);
Bundle bundle = this.getIntent().getExtras();
String startMode = bundle.getString("startMode");
if(startMode.equals("left")){
searchView.setVisibility(View.VISIBLE);
searchView2.setVisibility(View.GONE);
}else {
searchView.setVisibility(View.GONE);
searchView2.setVisibility(View.VISIBLE);
}
List<String> list=new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add("search key"+i);
}
// 一、 设置自动搜索内容
searchView.setSearchList(list).setHighLightColor(Color.RED).setSelectCallback((res) -> {
Snackbar.make(searchView,"选中:"+res, Snackbar.LENGTH_SHORT).setBackgroundTint(getColor(R.color.color_main)).show();
});
// 二、只要输入框内容
searchView2.setOnSubmitKey((searchKey) -> {
// 执行提交按钮
Snackbar.make(searchView,"获取输入的内容:"+searchKey, Snackbar.LENGTH_SHORT).setBackgroundTint(getColor(R.color.color_main)).show();
});
}
}
gitee传送门 https://gitee.com/Pino_W/search-view