首页 > 解决方案 > Android:带有一个编辑文本和微调器的 TextInputLayout

问题描述

我想创建这样的布局: 在此处输入图像描述

我想在 TextInputLayout 中添加一个微调器,并像这样显示 TextInputEditText 的提示。

我尝试制作自定义 TextInputLayout 但仍然无法为其添加微调器。

我已经用概述视图添加了这样的 TextInputLayout:-

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:textColorHint="@color/colorGreyView"
        android:textSize="20dp"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Mobile Number"/>
    </com.google.android.material.textfield.TextInputLayout>

标签: androidandroid-layoutandroid-textinputlayout

解决方案


执行'com.google.android.material:material:1.1.0-alpha08'

TextInputLayout ExposedDropdownMenu与 EditextText 一起使用并试试这个:

<com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Label"
        app:errorEnabled="true">

        <AutoCompleteTextView
            android:id="@+id/filled_exposed_dropdown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:editable="false" />

         <com.google.android.material.textfield.TextInputEditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </com.google.android.material.textfield.TextInputLayout>

根据要求调整宽度尺寸。


推荐阅读