XML属性
android:completionHint 下拉菜单标题
android:completionThreshold 输入多少个字符才会提示
android:dropDownHerght 下拉菜单高度
android:dropDownWidth 下拉菜单宽度
android:dropDownHorizontalOffset 下拉菜单与文本的水平偏移量。默认为对齐文本框
android:dropDownVerticalOffset 下拉菜单与文本的垂直偏移量。默认紧跟文本框
android:popupBackground 下拉菜单设置背景
列子
1.布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<AutoCompleteTextView
android:id="@+id/av"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="请输入搜索内容"
android:layout_weight="7"
android:completionThreshold="2"
android:text=""
/>
<Button
android:layout_weight="1"
android:text="搜索"
android:id="@+id/bn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
2.Activity
public class MainActivity extends AppCompatActivity {
private static final String[] name = {"有空you","淘宝天猫","美的电器部门",
"软件编程java","LG显示器","哈哈哈哈哈哈哈"};
private AutoCompleteTextView av;
private Button bn;
private ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
av = (AutoCompleteTextView) findViewById(R.id.av);
bn = (Button) findViewById(R.id.bn);
adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,name);
av.setAdapter(adapter);
bn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, av.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
}