[ACCEPTED]-Show the password with EditText-android-edittext

Accepted answer
Score: 68

I don't know exactly the specifics, but 4 this code should work:

checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(!isChecked) {
                    password.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                } else {
                    password.setInputType(129);
                }
            }
        });

129 is the input type 3 set when setting android:inputType="textPassword"

edit:

as mentioned in @user370305's 2 answer, 129 is the value of the bitwise or 1 operation when you do

password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
Score: 49

This is not an answer,

Answer already given 7 and accepted..

I just want to clarify about 6 129

password.setInputType(129);

is Actually,

password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

'|' is not a pipe, it's a bitwise OR. It takes two binary 5 numbers and if either of the bits of equal 4 value are 1,

How this relates to the input 3 type: Each of the InputTypes are actually 2 just ints. TYPE_CLASS_TEXT is 1, and TYPE_TEXT_VARIATION_PASSWORD is 128 (or 10000000).

Perform a bitwise OR on them:

00000001

10000000

------------

10000001 which is 129.

Try 1 entering input.setInputType(129); instead, you'll see it'll work. :)

Score: 16

I think you are using the wrong function. I 1 make that way and work perfectly:

passwordEditView = (EditText) rootView.findViewById(R.id.password);
final CheckBox showPasswordCheckBox = (CheckBox) rootView.findViewById(R.id.checkbox);
showPasswordCheckBox.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        if (showPasswordCheckBox.isChecked()){
            passwordEditView.setTransformationMethod(null);
        }else{
            passwordEditView.setTransformationMethod(new PasswordTransformationMethod());
       }
    }
});
Score: 10

This might help you mate

checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // checkbox status is changed from uncheck to checked.
        if (!isChecked) {
            // show password
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        } else {
            // hide password
            editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        }
    }
});

0

Score: 3

The Password Visibility Toggle feature has 6 been added to support library version 24.2.0 5 enabling you to toggle the password straight 4 from the password field without the need 3 for a CheckBox.

You can make that work basically 2 by setting an inputType of password on the 1 TextInputEditText. Here's how to do that:

<android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/password"
            android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
Score: 3

use app:passwordToggleEnabled = true; available 1 from Android support library version 24.2.0.

  <android.support.design.widget.TextInputLayout
    android:id="@+id/input_layout_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"
    app:passwordToggleEnabled="true"
    tools:visibility="visible"
    android:layout_marginBottom="@dimen/space_medium">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/input_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:imeOptions="actionDone"
        android:imeActionLabel="@string/btn_sign_in"
        android:hint="@string/hint_password" />

</android.support.design.widget.TextInputLayout>
Score: 2

instead of visible password, can you try 1 with TYPE_TEXT_VARIATION_NORMAL

public void ShowPassword() {
password.setInputType((cb.isChecked()) ? 
InputType.TYPE_TEXT_VARIATION_NORMAL : InputType.TYPE_TEXT_VARIATION_PASSWORD;
}
Score: 1

Call this method inside your OnCheckedChangedListener

 public static void toggleShowPassword(boolean show, EditText editText) {
    if (show)
        editText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
    else
        editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    editText.setSelection(editText.length());
}

The EditText cursor 2 resets its position after changing the InputType that's 1 why we add the last line editText.setSelection(editText.length())

Score: 1

This will work -

public void ShowPassword() {
    if (cb.isChecked()) {
        password.setInputType(InputType.TYPE_CLASS_TEXT);
    } else {
        password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
}

0

Score: 0

on the off chance that you are using Xamarin 4 (Visual Studio Mac as it's now called) you 3 can achieve it this way (I used a Switch)

 /// <summary>
 /// Toggles the password.
 /// </summary>
 /// <param name="field">Field.</param>
 /// <param name="isChecked">If set to <c>true</c> is checked.</param>
 private void TogglePassword(TextView field, bool isChecked)
 {
      /// masks with password character
      if (isChecked)
      {
           field.TransformationMethod = new PasswordTransformationMethod();
      }
      /// unmasks password
      else
      {
           field.TransformationMethod = null;
      }

Then 2 on your Switch .click do something like 1 this

switch.Click += delegate {
            TogglePassword(textView, switch.Checked);
        };

More Related questions