这期内容当中小编将会给大家带来有关Android应用中SearchView属性的作用有哪些,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。SearchView是搜索框组件,它可以让用户在文本框里输入文字,通
这期内容当中小编将会给大家带来有关Android应用中SearchView属性的作用有哪些,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
SearchView是搜索框组件,它可以让用户在文本框里输入文字,通过监听器取得用户的输入,当用户点击搜索时,监听器执行实际的搜索。
SearchView组件的常用方法如下:
①setIconifiedByDefault(boolean iconified) ===> 设置搜索框默认是否自动缩小为图标。
②setOnQueryTextListener(SearchView,OnQueryTextListener listener) ===> 为搜索框设置监听器
③setSubmitButtonEnabled(boolean enabled) ===> 设置是否显示搜索按钮
④setQueryHint(CharSequence hint) ===> 设置搜索框内的默认显示的提示文本
为SearchView增加一个配套的ListView,则可以为其增加自动完成的功能,即ListView用于为SearchView显示自动补齐列表
具体实现代码如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="Http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 顶一个SearchView --> <SearchView android:id="@+id/sv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- 为SearchView定义自动补齐的ListView--> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> </LinearLayout>
--结束END--
本文标题: Android应用中SearchView属性的作用有哪些
本文链接: https://www.lsjlt.com/news/223098.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-11
2024-05-11
2024-05-11
2024-05-11
2024-05-11
2024-05-11
2024-05-11
2024-05-11
2024-05-11
2024-05-11
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0