【问题标题】:SetError Icon overlaps other edittext iconsSetError 图标与其他 edittext 图标重叠
【发布时间】:2020-02-29 05:27:38
【问题描述】:

setError 图标与我在编辑文本中的其他图标重叠

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/text_input_layout_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:paddingTop="10dp"
    app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view_separator_2"
    app:passwordToggleDrawable="@drawable/custom_show_hide_password_black"
    app:passwordToggleEnabled="true"
    app:passwordToggleTint="@color/black">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/login_password"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="10"
            android:background="@null"
            android:contentDescription="@string/acc_password"
            android:hint="@string/password"
            android:imeOptions="actionDone"
            android:inputType="textPassword"
            android:padding="10dp"
            android:textColor="@color/color_1D1D1D"
            android:textColorHint="@color/color_5A5D63"
            android:textSize="14sp"
            tools:text="Password" />

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

在此图像中,眼睛图标和感叹号重叠,我希望它并排先显示错误消息图标,然后是眼睛图标,有什么办法吗?

【问题讨论】:

  • 请添加您的代码
  • 请添加您的 layout.xml

标签: java android xml android-styles


【解决方案1】:

你只需要调用这个函数。

passwordTxtInputLayout = findViewById(R.id.text_input_layout_password);
    etPassword = findViewById(R.id.login_password);
    if (etPassword != null) {
        etPassword.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {


            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                passwordTxtInputLayout.setEndIconVisible(true);

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

并在密码长度小于等于零时调用此函数

passwordTxtInputLayout.setEndIconVisible(false);

确保在调用 setError 之前调用此函数,否则 eyeIcon 将被禁用。

【讨论】:

    【解决方案2】:

    试试这个代码。由于您在TextInputLayout 中有您的app:passwordToggleDrawable,因此您也应该在textInputLayout 中调用setError()。请参考下面的代码

    TextInputLayout textInputLayout = findViewById(R.id.text_input_layout_password);
    textInputLayout.setError("Password is empty");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多