ItaliaIshan
ItaliaIshan

Reputation: 67

How to toggle between hide and view password Xamarin.Android

<EditText
    android:id="@+id/passWordEditText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:inputType="textPassword"
    android:password="true"/>

What should be done to toggle show/hide password in Xamarin.Android?

Upvotes: 2

Views: 2848

Answers (2)

currarpickt
currarpickt

Reputation: 2302

You could use TextInputLayout and set passwordToggleEnabled as true. It will automatically handle the toggle between show and hide password.

<android.support.design.widget.TextInputLayout
            android:id="@+id/textInputLayoutPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:passwordToggleEnabled="true">
            <android.support.design.widget.TextInputEditText
                android:id="@+id/editTextPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/password"
                android:singleLine="true"
                android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>

Upvotes: 4

Ricardo Romo
Ricardo Romo

Reputation: 1624

You can use the InputType property of edittext and change it to show/hide. Take a look on the next code.

    bool isVisible;
    void Button_Click(object sender, System.EventArgs e)
    {
        if(isVisible)
            editText.InputType = Android.Text.InputTypes.TextVariationVisiblePassword;
        else
            editText.InputType = Android.Text.InputTypes.TextVariationPassword | Android.Text.InputTypes.ClassText;

        editText.SetSelection(editText.Text.Length);
        isVisible = !isVisible;
    }

Upvotes: 1

Related Questions