Ser*_*D15 2 android android-edittext
我希望在获得焦点时EditText将其显示hint为标题,并显示一个下拉列表以使用户自动完成它。这些功能分别在TextInputEditText和上可用AutoCompleteTextView。除了EditText使用继承创建自定义方式之外,还有其他方法可以实现这两者吗?提前致谢。
如果您需要新的Material Design库和Android Jetpack组件,请使用以下XML布局代码:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Example TextInputLayout">
<androidx.appcompat.widget.AppCompatAutoCompleteTextView
style="@style/Widget.MaterialComponents.TextInputEditText.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
请注意,使用此库时,您应该在TextInputLayout(而不是AppCompatAutoCompleteTextView)上设置提示。
如果你想替代概括文本字段版本,替换FilledBox用OutlinedBox在两个样式属性。
| 归档时间: |
|
| 查看次数: |
1617 次 |
| 最近记录: |