Reputation: 11
The following link shows the main problem (Link) As you can see, there is overlap between the password visibility icon and the validation icon (when it dynamically appears). I want to know a simple way to position the icons so that they will work together, is that possible?
The password toggle
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayoutWifiPW"
android:layout_width="600dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayoutWifiSSID"
app:passwordToggleDrawable="@drawable/passwordtoggle"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/md_blue_500">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/password"
android:layout_width="568dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif"
android:hint="@string/password"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/SSID" />
Validation methods
private void validateWIFI(final Context context) {
if (SSID.length() == 0 ) {
dialogButtonTrueOrFalse(mDialog, false);
SSID.setError(context.getString(R.string.error_ssid_empty));
}else if (PWD.length() > 0 && PWD.length() < 8) {
dialogButtonTrueOrFalse(mDialog, false);
PWD.setError(context.getString(R.string.error_pwd_length));
}else {
dialogButtonTrueOrFalse(mDialog,true);
}
}
public void dialogButtonTrueOrFalse(AlertDialog mDialog, Boolean button){
if (button){
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setClickable(true);
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}else if (!button){
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setClickable(false);
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
}
Upvotes: 1
Views: 600
Reputation: 1030
i tink you setError to CommonTextInputEditText and its better that you setError TextInputLayout instead of your CommonTextInputEditText in your java codes
TextInputLayout passwordInputLayout =findViewById(R.id.textInputLayoutWifiPW);
passwordInputLayout.setError("your textError");
you can use this refrence to learn about in
also you can setErrorStyle to your edittext and add margin to it
yourEditText.setError(Html.fromHtml("<//todo...'>this is the error</font>"));
Upvotes: 1
Reputation: 145
for change drawable, create a selector like below
password_toggle_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_password_visible" android:state_checked="true"/>
<item android:drawable="@drawable/ic_password_hidden"/>
</selector>
then assign to TextInputLayout like below:
<android.support.design.widget.TextInputLayout
android:id="@+id/PasswordLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
app:passwordToggleEnabled="true"
**app:passwordToggleDrawable="@drawable/password_toggle_drawable"**
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CommonTextInputEditText
android:id="@+id/PasswordEditText"
android:padding="0dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
for height, I used below code after inflating:
CheckableImageButton text_input_password_toggle = (CheckableImageButton) PasswordLayout().findViewById(android.support.design.R.id.text_input_password_toggle);
text_input_password_toggle.setMinimumHeight(0);
PasswordEditText().setMinHeight(0);
PasswordEditText().setMinimumHeight(0);
Upvotes: 1