Android 搜索框:SearchView 的属性和用法详解
来源:互联网 发布:龙之研究能量矩阵 编辑:程序博客网 时间:2024/05/16 08:51
转载请标明出处: http://blog.csdn.net/airsaid/article/details/51087226
本文出自:周游的博客
- SearchView简介
- SearchView属性
- SearchView使用
SearchView简介
SearchView是Android原生的搜索框控件,它提供了一个用户界面,用于用户搜索查询。
SearchView默认是展示一个search的icon,点击icon展开搜索框,如果你想让搜索框默认就展开,可以通过setIconifiedByDefault(false);实现。
SearchView属性
SearchView使用
- xml中定义SearchView:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="15dp" android:orientation="vertical" tools:context="com.airsaid.searchviewdemo.MainActivity"> <SearchView android:id="@+id/searchView" android:layout_width="match_parent" android:layout_height="wrap_content" android:iconifiedByDefault="false" android:queryHint="请输入搜索内容" /> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /></LinearLayout>
- Main代码:
public class MainActivity extends AppCompatActivity { private String[] mStrs = {"aaa", "bbb", "ccc", "airsaid"}; private SearchView mSearchView; private ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSearchView = (SearchView) findViewById(R.id.searchView); mListView = (ListView) findViewById(R.id.listView); mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrs)); mListView.setTextFilterEnabled(true); // 设置搜索文本监听 mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { // 当点击搜索按钮时触发该方法 @Override public boolean onQueryTextSubmit(String query) { return false; } // 当搜索内容改变时触发该方法 @Override public boolean onQueryTextChange(String newText) { if (!TextUtils.isEmpty(newText)){ mListView.setFilterText(newText); }else{ mListView.clearTextFilter(); } return false; } }); }}
- 效果截图:
Demo下载:http://download.csdn.net/detail/airsaid/9483985
2 2
- Android 搜索框:SearchView 的属性和用法详解
- Android 搜索框:SearchView 的属性和用法详解
- Android 搜索框:SearchView 的属性和用法详解
- Android中的搜索框(SearchView)的功能和用法
- Android中的搜索框(SearchView)的功能和用法
- Android搜索控件SearchView的用法
- 登陆Android中的搜索框(SearchView)的功能和用法
- 搜索框(SearchView)详解
- 搜索控件SearchView的用法
- 搜索控件SearchView的用法
- Android中SearchView的功能和用法
- Android的搜索框SearchView的用法-android学习之旅(三十九)
- 修改SearchView搜索框的下划线.(或着其他属性)
- Android SearchView 修改hint颜色和搜索字的颜色
- 一个最简单的基于Android SearchView的搜索框
- Android searchView和listview实现搜索
- Android searchView和listview实现搜索
- Android searchView和listview实现搜索
- 页面Tab切点击切换
- Mac OS X系统下修改wifi共享的默认网段
- hihoCoder[Offer收割]编程练习赛1题目解析
- nginx+tomcat+redis完成session共享
- serialVersionUID作用
- Android 搜索框:SearchView 的属性和用法详解
- RadioGroup OnCheckedChange
- 《leetCode》:Counting Bits
- BC400_430 作业备份-使用报表查询员工工资信息
- Ngnix安装error: the HTTP rewrite module requires the PCRE library.
- iOS 高效添加圆角效果实战讲解
- 十个随机数求和
- vb7
- Android官方开发文档Training系列课程中文版:分享文件之请求一个共享文件