标签:android autocompletetextview
android:completionHint-->设置下拉菜单中的提示标题-->对应方法:setCompletionHint(CharSequence)
android:completionHintView-->设置下拉菜单中提示标题的视图
android:completionThreshold-->设置用户至少输入几个字符才会有提示-->对应方法:setThreshold(int)
android:dropDownAnchor-->设置下拉菜单的定位“描点”组件,如果没有指定该属性,将使用该TextView本身作为定位“描点”组件-->对应方法:setDropDownAnchor(int)
android:dropDownHeight-->设置下拉菜单的高度-->对应方法:setDropDownHeight(int)
android:dropDownHorizontalOffset-->设置下拉菜单与文本框之间的水平偏移。默认为与文本框左对齐
andorid:dropDownVerticalOffset-->设置。。。。。。。。。。。。垂直偏移。。。。。。。。紧挨。
android:dropDownWidth-->设置下拉菜单的宽度-->对应放法:setDropDownWidth
android:popupBackground-->设置下拉菜单的背景-->对应方法:setDropDownBackgroundResource(int)
下面我们看个实例:
<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:orientation="vertical" tools:context=".MainActivity"> <TextView android:layout_marginTop="5dp" android:textColor="#382aff" android:textSize="24sp" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/title" /> <!--指定输入一个字符后提示--> <AutoCompleteTextView android:id="@+id/auto" android:singleLine="true" android:completionHint="@string/selectBook" android:completionThreshold="1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <MultiAutoCompleteTextView android:id="@+id/mAuto" android:completionThreshold="1" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
package cn.edu.hpu.acm.autoCompleteTextViewTest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.MultiAutoCompleteTextView; public class MainActivity extends AppCompatActivity { private AutoCompleteTextView autoCompleteTextView; private MultiAutoCompleteTextView multiAutoCompleteTextView; private String[] books = new String[]{ "疯狂Java讲义", "疯狂Android讲义", "疯狂Ajax讲义", "疯狂Workflow讲义" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.auto); multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.mAuto); //创建一个ArrayAdapter,封装数组 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,books); //设置Adapter autoCompleteTextView.setAdapter(adapter); multiAutoCompleteTextView.setAdapter(adapter); //设置分隔符 multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
第22章:自动完成文本框AutoCompleteTextView的用法
标签:android autocompletetextview
原文地址:http://blog.csdn.net/zhangpan_soft/article/details/47414487