Android 自动提示控件 AutoCompleteTextView

Android About 1,030 words

代码

输入框中输入我们想要输入的信息就会出现其他与其相关的提示信息 44517621390.jpg

<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);
    }
}

常用属性

属性 含义
android:completionHint 设置出现在下拉菜单中的提示标题
android:completionThreshold 设置用户至少输入多少个字符才会显示提示
android:dropDownHorizontalOffset 下拉菜单于文本框之间的水平偏移。默认与文本框左对齐
android:dropDownHeight 下拉菜单的高度
android:dropDownWidth 下拉菜单的宽度
android:singleLine 单行显示
android:dropDownVerticalOffset 垂直偏移量
Views: 2,474 · Posted: 2019-04-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh