【问题标题】:Android: TextInputLayout with one Edit Text and spinnerAndroid:带有一个编辑文本和微调器的 TextInputLayout
【发布时间】:2019-11-25 00:59:21
【问题描述】:

我想创建这样的布局:

我想在 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>

【问题讨论】:

  • 所以你可以使用水平线性布局作为父级。 Spinner 和文本输入布局都将使用 weight 属性分开。您需要将边框背景应用于该父 linrarlayout。
  • @Piyush 但这不允许提示浮动。应该作为标签出现的提示隐藏起来。这个我已经试过了。
  • 你能检查一下12。可能会有帮助
  • @Piyush 两个链接都是针对单个孩子的。两个链接都有助于为微调器添加浮动标签,但没有关于两个嵌套子级的信息。
  • 所以你可以使用相对或框架布局来代替线性布局

标签: android android-layout android-textinputlayout


【解决方案1】:

实现'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>

根据需要调整宽度大小。

【讨论】:

  • 我尝试了相同的依赖项和相同的样式,但 xml 无法解析相同的内容。这样做时显示二进制 XML 膨胀错误
  • 尝试使用最新的依赖来解决样式问题: implementation 'com.google.android.material:material:1.1.0-alpha08'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多