问题:带有提示重叠的 OutlinedBox 错误的 TextInputLayout

Ask*_*iip 2 xml android android-textinputlayout textinputlayout material-components-android

当我想在 EditText 中写我的提示与 OutlinedBox 重叠时,我的提示有问题,所以我不明白是什么问题。所以这是我的代码

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

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/text_input_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:drawableStart="@drawable/ic_action_name"
            android:hint="@string/Enter_Username"
            android:inputType="textPersonName"/>
    </com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

我的问题:

在此处输入图片说明

Gab*_*tti 5

删除android:layout_margin="10dp"你的TextInputEditText

在此处输入图片说明

最好的解决办法应该是:

    <com.google.android.material.textfield.TextInputLayout
        app:startIconDrawable="@drawable/...."
        android:hint="Enter_Username"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        ...>

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/text_input_username"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"/>

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


小智 0

填充文本有帮助吗?也许用一些空格填充字符串的开头,或者在 xml 中用android:paddingLeft=5dp