如何使用 OutlinedBox 样式从 TextInputLayout 中删除浮动标签?

Nom*_*sta 3 android material-components material-components-android

TextInputLayout处于聚焦模式时,有没有办法删除浮动标签(提示)?

当我尝试在app:hintEnabled="false"inside 中设置和提示时TextInputeEditTextTextInputLayout通过隐藏顶部笔画表现得很奇怪。

<com.google.android.material.textfield.TextInputLayout
      style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="Text">

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

</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

重要的是我在版本中使用材料组件 1.1.0-alpha01.

编辑

这是它的样子(当输入未聚焦时):

截屏

顶部行程被切断。

Joe*_*n93 7

是的,有一种相当简单的方法可以删除浮动标签提示,并且只在TextInputLayout.

这可以通过禁用 中的提示TextInputLayout并在 上设置提示来轻松实现,TextInputEditText而不是像TextInputLayout这样:

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hintEnabled="false">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="hint text comes here" />

</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

结果看起来像这样:在此输入图像描述

添加一些文本后,它将如下所示:在此输入图像描述

我在 Material Components v1.2.0 中尝试过这个


小智 5

只需以EditText 编程方式设置提示并app:hintEnabled="false"从您的提示中删除TextInputLayout,在我的情况下有效:)


Dee*_*Shu 0

尝试将文本布局和编辑文本的提示设置为空:-

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

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

</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

如果您想使用提示,那么您可以使用自定义可绘制对象作为 EditText 的背景:-

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners android:radius="10dp"/>
    <solid android:color="#ffffff"/>
    <stroke android:color="#000000"
    android:width="2dp"/>

</shape>
Run Code Online (Sandbox Code Playgroud)