TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
在输入框中输入我们想要输入的信息就会出现其他与其相关的提示信息,这种效果在Android中是用AutoCompleteTextView实现的。
- <AutoCompleteTextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/autotext"
- />
复制代码
- public class MainActivity extends Activity {
- private AutoCompleteTextView autotext;
- private ArrayAdapter<String> arrayAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.test);
- autotext =(AutoCompleteTextView) findViewById(R.id.autotext);
- String [] arr={"aa","aab","aac"};
- arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arr);
- autotext.setAdapter(arrayAdapter);
- }
- }
复制代码
AutoCompleteTextView常用属性
android:completionHint
设置出现在下拉菜单中的提示标题
android:completionThreshold
设置用户至少输入多少个字符才会显示提示
android:dropDownHorizontalOffset
下拉菜单于文本框之间的水平偏移。默认与文本框左对齐
android:dropDownHeight
下拉菜单的高度
android:dropDownWidth
下拉菜单的宽度
android:singleLine
单行显示
android:dropDownVerticalOffset
垂直偏移量
相关文章:
控件AutoCompleteTextView 客户端保存搜索历史自动提示 |
|