使用场景
AutoCompleteEditText只有开始输入并且与输入的字符有匹配的时候才弹出下拉列表.Spinner的缺点是不可以编辑.所以本文介绍如何使用EditText+ListPopupWindow实现可编辑的下拉列表.使用场景可以是有记住密码功能的登录框.
给EditText增加上下箭头
我们需要一个箭头图片,放在EditText的右面,用来点击后弹出下拉列表.如图所示
要想实现这个很容易,只需要在布局文件中给EditText设置一个drawableRight的属性.
android:layout_width="match_parent"android:layout_height="wrap_content"android:drawableRight="@drawable/pull_down1"/>
如何在点击的时候切换箭头的方向
切换箭头的上下方向,实际上就是重新设置EditText的drawableRight.这就需要动态的设置EditText的drawableRight.
setCompoundDrawables(left, top, right, bottom);
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
意思是设置Drawable显示在text的左、上、右、下位置。
但是两者有些区别: setCompoundDrawables 画的drawable的宽高是按