Reputation: 305
can we hide passwordToggle temporary when user get warning error and display it back when user fill the EditText with some data, look at this picture
if i tried this
if (etPassNow.length() == 0){
etPassNow.setError("No data");
textInputLayout.setPasswordVisibilityToggleEnabled(false);
}
then the result is like this
, but this is what i want
there's an icon error above error warning,
has anyone ever meet this issue? Thank you
This is my xml
<android.support.design.widget.TextInputLayout
android:id="@+id/ti_new_pass"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
app:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
android:id="@+id/et_new_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Kata Sandi Baru"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:paddingBottom="25dp"
android:paddingStart="30dp"
android:singleLine="true"
android:textColor="@color/dc_gray"
android:textSize="16sp"/>
</android.support.design.widget.TextInputLayout>
Upvotes: 2
Views: 1878
Reputation: 123
The above used method has been deprecated hence no longer used so for this we have to use new Method
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) {
}
});
and call this function whenever the password length is less than and equal to zero
passwordTxtInputLayout.setEndIconVisible(false);
Make sure this function should be called before calling setError otherwise eyeIcon will be disable.
Upvotes: 3
Reputation: 305
This is my conclusion after getting trial error, i'm checking the error if field empty in onClick action
if (etPassNow.length() == 0)
etPassNow.setError("Please fill data");
and for passwordToggle i activate it in onTextChange
etPassNow.addTextChangeListener(this);
public void onTextChanged(CharSequence s, int start, int before, int count){
if (etPassNow.getText().toString().length() > 0)
textInputLayout.setPasswordVisibilityToggleEnabled(true);
else
textInputLayout.setPasswordVisibilityToggleEnabled(false);
}
this is the easiest way for my case
Upvotes: 2
Reputation: 4643
try this
if (etPassNow.length() == 0) {
etPassNow.setError("No data");
etPassNow.setTransformationMethod(null);
} else {
etPassword.setTransformationMethod(new PasswordTransformationMethod());
}
Upvotes: 0