android - TextInputLayout 和 AutoCompleteTextView

标签 android autocomplete android-edittext autocompletetextview android-textinputlayout

我正在使用 TextInputLayout在我的 Android 应用程序中为我的输入字段实现整洁的 float 标签效果。我知道我应该使用 TextInputEditText以及允许在横向模式下显示提示并且输入填满整个屏幕。

但是,在我的某些输入字段中,我使用 AutoCompleteTextView 进行了自动完成。 (IMO 有一个非常不一致的名称——“TextView”而不是“EditText”——但那是另一回事了)并且显然直接继承自 EditText。因此它没有 TextInputEditText 带来的相同功能。

所以我想知道是否有一种方法可以实现相同的横向提示功能(也就是说,无需我自己的 TextInputAutoCompleteTextView 实现)并避免产生的 lint 警告.我在这里错过了什么吗?我想我知道他们没有为这个特定的东西制作 EditText 的所有直接和间接子类的自定义版本,所以我应该自己制作吗?

最佳答案

现在,使用 AndroidX,您无需自定义任何内容。
只需添加 Material 组件样式(在1.1.0-alpha06中添加,参见release notes)。

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Example TextInputLayout">

    <androidx.appcompat.widget.AppCompatAutoCompleteTextView
    style="@style/Widget.MaterialComponents.AutoCompleteTextView.FilledBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout> 

关于android - TextInputLayout 和 AutoCompleteTextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39431378/

相关文章:

Jquery,使用 json 自动完成,id 与显示值

javascript - 如何隐藏空白数组并只保留数组的值/名称?

android - EditText 和 MultiAutoCompleteTextView 建议

javascript - cordova 中的 navigator.geolocation.getCurrentPosition 仅提供 10 米的精度

java - 二维边界框与旋转的碰撞

android - Appengine连接Android项目-添加账号

android - 无法获取 Crashlytics 中 native 崩溃的堆栈跟踪

android - 如何使用注册设备的电子邮件 ID 自动填充电子邮件编辑文本

android - 使 editText 可以键入但文本在 Android 中不会更改?

Android EditText 光标下奇怪的 float 白框