wordpress网站做app,微网站和门户网站的区别,wordpress如何cdn加速,网站服务器ipv6在日常开发中经常会遇到这种需求#xff0c;EditText既需要可以筛选#xff0c;又可以点击选择。这里筛选功能用的是AutoCompleteTextView#xff0c;选择功能使用的是第三方库https://github.com/kongzue/DialogX。 Android AutoCompleteTextView(自动完成文本框)的基本使用…
在日常开发中经常会遇到这种需求EditText既需要可以筛选又可以点击选择。这里筛选功能用的是AutoCompleteTextView选择功能使用的是第三方库https://github.com/kongzue/DialogX。 Android AutoCompleteTextView(自动完成文本框)的基本使用
布局文件activity_main.xml
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationverticaltools:context.MainActivityAutoCompleteTextViewandroid:idid/atv_contentandroid:layout_widthmatch_parentandroid:layout_height48dpandroid:completionHint请输入搜索内容android:completionThreshold1android:dropDownHorizontalOffset5dp /MultiAutoCompleteTextViewandroid:idid/matv_contentandroid:layout_widthmatch_parentandroid:layout_height48dpandroid:completionThreshold1android:dropDownHorizontalOffset5dpandroid:text //LinearLayout
MainActivity.java
public class MainActivity extends AppCompatActivity {private AutoCompleteTextView atv_content;private MultiAutoCompleteTextView matv_content;private static final String[] data new String[]{小猪猪, 小狗狗, 小鸡鸡, 小猫猫, 小咪咪};Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);atv_content (AutoCompleteTextView) findViewById(R.id.atv_content);matv_content (MultiAutoCompleteTextView) findViewById(R.id.matv_content);ArrayAdapterString adapter new ArrayAdapterString(MainActivity.this, android.R.layout.simple_dropdown_item_1line, data);atv_content.setAdapter(adapter);ArrayAdapterString adapter2 new ArrayAdapterString(getApplicationContext(), android.R.layout.simple_dropdown_item_1line, data);matv_content.setAdapter(adapter);matv_content.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());}
} 相关属性 android:completionHint设置下拉菜单中的提示标题android:completionHintView定义提示视图中显示下拉菜单android:completionThreshold指定用户至少输入多少个字符才会显示提示android:dropDownAnchor设置下拉菜单的定位锚点组件如果没有指定改属性 将使用该TextView作为定位锚点组件android:dropDownHeight设置下拉菜单的高度android:dropDownWidth设置下拉菜单的宽度android:dropDownHorizontalOffset指定下拉菜单与文本之间的水平间距android:dropDownVerticalOffset指定下拉菜单与文本之间的竖直间距android:dropDownSelector设置下拉菜单点击效果android:popupBackground设置下拉菜单的背景 另外其实还有个MultiAutoCompleteTextView(多提示项的自动完成文本框) 和这个AutoCompleteTextView作用差不多属性也一样具体区别在哪里 我们在下面的代码中来体验~另外这两个都是全词匹配的比如小猪猪 你输入小-会提示小猪猪但是输入猪猪-却不会提示小猪猪 此外还增加了一些UI方面的交互体验使用起来更丝滑。
需要源码的可去下载为了交互体验也是花了不少时间https://download.csdn.net/download/iromkoear/88335284?spm1001.2014.3001.5501