android文本框自动补全,[Android]AutoCompleteTextView自动补全文本框
当我们在做项目的时候,往往有着这样的需求:(1)在登陆的时候,在输入的账号的过程中弹出补全账号的提示(2)在搜索的时候,在输入搜索词的过程中弹出补全搜索词的提示,就像:
而这时,AutoCompleteTextView自动补全文本框则可以简易的帮我们解决这个难题:
实现代码:
activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.xiaoyan.xiejinxiong.testintent.MainActivity">
android:id="@+id/actv"
android:layout_width="200dp"
android:layout_height="wrap_content" />
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.actv);
ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, new String[]{"String", "studio", "steam"});
autoCompleteTextView.setAdapter(arrayAdapter);
}
}效果便是上图了。
不过,这个提示的布局是系统默认布局,我们可以根据自己的需求去修改其布局,将
ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, new String[]{"String", "studio", "steam"});修改为:
ArrayAdapter arrayAdapter = new ArrayAdapter(this, R.layout.text_list_item, R.id.tvlist,new String[]{"String", "studio", "steam"});text_list_item.xml
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="match_parent">
android:id="@+id/tvlist"
android:textColor="@android:color/holo_blue_bright"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
效果图:
android文本框自动补全,[Android]AutoCompleteTextView自动补全文本框相关推荐
- android输入自动补全,Android用户输入自动提示控件AutoCompleteTextView使用方法
一.简介 1.AutoCompleteTextView的作用 2.AutoCompleteTextView的类结构图 也就是拥有EditText的各种功能 3.AutoCompleteTextView ...
- Android使用EditView输入框输入身份证时,自动补全身份证最后一位验证位
Android使用EditView输入框输入身份证时,自动补全身份证最后一位验证位 下面直接贴出代码 //监听输入框文本长度,并自动补全身份证最后一位验证位 mEdit.addTextChangedL ...
- android--Spinne下拉列表视图r、ArrayAdapter数组适配器、SimpleAdapte简单适配器r、AutoCompleteTextView自动提示完成文本框
在学习这些之前呢,我们先来了解一下关于Spinner.ArrayAdapter.SimpleAdapter.AutoCompleteTextView的作用: Spinner :下拉列表视图 ,他的父类 ...
- ImmersionBar篇Android实现全屏配置 自动横屏
ImmersionBar篇Android实现全屏配置 自动横屏 项目下的gradle配置添加 // 基础依赖包,必须要依赖 implementation 'com.gyf.immersionbar:i ...
- android动画结束弹出文本框,学完(Android疯狂猜歌 5-2 实现待选文字框点击事件)课程出现的小问题...
疯狂猜歌 5-2 实现待选文字框点击事件 自定义的GirdView中,holder的值是a0...a23 holder如果定义在getView 里就没事,点击a1就显示a1,但是,如果定义在成员变量 ...
- devc代码补全没效果_从零开始写文本编辑器(二十八):自动补全(上)
前言 我本没打算这么早就写"自动补全"功能的. 但是在写XML资源编辑时,为了实现自动引用已有资源@string/xxx,需要一个合适的列表来让我选择.这样能防止拼写错误. 也就是 ...
- android 擦除图片_在“提示”框中:停止自动运行,Android的电源板和安全DVD擦除...
android 擦除图片 This week we're kicking off a new series here at How-To Geek focused on awesome reader ...
- 最全Android Studio插件整理
现在Android的开发者基本上都使用Android Studio进行开发(如果你还在使用eclipse那也行,毕竟你乐意怎么样都行).使用好Android Studio插件能大量的减少我们的工作量. ...
- 最新最全 Android 常用开源库总结
点击上方"码农突围",马上关注这里是码农充电第一站,回复"666",获取一份专属大礼包 真爱,请设置"星标"或点个"在看" ...
最新文章
- Michael Jordan:当下的AI其实都是伪“AI”
- 自媒体时代的主流媒体不可替代
- 如何将Git上的项目克隆到idea中
- ACL 2020 | 多编码器是否能够捕获篇章级信息?
- knn实战:如何对手写数字进行识别?
- Apache Iceberg 快速入门
- 如何使create-react-app与Node Back-end API一起使用
- hp M1530一体机无法在OEM系统下安装驱动
- 一键清空服务器文件,一键清理操作系统垃圾文件的BAT
- 4字节 经纬度_【笔记】进制转换和经度纬度
- qq服务器拒绝发送文件什么意思,QQ提示服务器拒绝发送离线文件是什么意思 - 卡饭网...
- VB 清除数组中全部元素的值
- 吴恩达机器学习(十五)—— 应用实例:图片文字识别
- 我们常说祝你一切顺利,实际上,顺利的状态是危险的,因为顺利意味着怠惰和懒于思考,是会让人失去奋斗的意志,丧失竞争力。
- python_安卓——canv
- NRF51822——LCD128X64驱动
- 这些硬盘参数你都懂得吗?
- 工作记录:8个有用的JS技巧
- MPI编译环境及编译器介绍
- JavaScript匿名函数(自调用函数)