SetError 图标与其他 edittext 图标重叠
SetError Icon overlaps other edittext icons
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>
这张图眼睛图标和感叹号是重叠的,我想先showerror message icon再是眼睛图标并排,请问有什么办法吗?
试试这个代码。由于您在 TextInputLayout
中有 app:passwordToggleDrawable
,因此您也应该在 textInputLayout
中调用 setError()
。请参考以下代码
TextInputLayout textInputLayout = findViewById(R.id.text_input_layout_password);
textInputLayout.setError("Password is empty");
你只需要调用这个函数即可。
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 将被禁用。
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>
这张图眼睛图标和感叹号是重叠的,我想先showerror message icon再是眼睛图标并排,请问有什么办法吗?
试试这个代码。由于您在 TextInputLayout
中有 app:passwordToggleDrawable
,因此您也应该在 textInputLayout
中调用 setError()
。请参考以下代码
TextInputLayout textInputLayout = findViewById(R.id.text_input_layout_password);
textInputLayout.setError("Password is empty");
你只需要调用这个函数即可。
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 将被禁用。