【问题标题】:EditText setError icon and endIconMode are fusedEditText setError icon 和 endIconMode 融合
【发布时间】:2020-12-17 16:14:08
【问题描述】:

如标题所说,我的setError图标和endIconMode融合为一体

基本上我希望 endIconMode 在左边或右边一点。我该怎么做?

这里是 Java:

 private void userLogin() {
            String password = passwordEditText.getText().toString().trim();

         if (password.length() < 6) {
            passwordEditText.setError("Erorr Message" );
            passwordEditText.requestFocus();
            return;
        }

这里是xml:

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textPasswordField"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginLeft="32dp"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:hint="Inserisci la Password!"
        app:boxBackgroundMode="outline"
        app:boxCornerRadiusBottomEnd="16dp"
        app:boxCornerRadiusBottomStart="16dp"
        app:boxCornerRadiusTopEnd="16dp"
        app:boxCornerRadiusTopStart="16dp"
        app:endIconMode="password_toggle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.55"
        app:startIconDrawable="@drawable/icons8_key_24">

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

    </com.google.android.material.textfield.TextInputLayout>

【问题讨论】:

    标签: java xml android-studio


    【解决方案1】:

    一种快速的解决方案是使用填充将错误消息移到左侧。

    <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/passwordEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingRight="40dp"
                    android:inputType="textPassword" />
    

    看起来像这样。

    【讨论】:

    • 成功了,谢谢!但是要注意宽度和高度,因为它会改变everyting。我让 EditText 更大
    • 确实如此。 paddingRight 固定为 40 dp,这不是一个好的解决方案,但可以解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-25
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多