Como alternair entre ocultair e visualizair senha

Existe uma maneira inteligente de permitir que o user troque entre ocultair e view senha em um android EditText? Uma série de aplicativos baseados em PC permitem que o user faça isso.

  • Erro do agente da New Relic Android com gradle
  • Existe de qualquer maneira paira remoview um onTouchListener de um object de exibição?
  • Em HTML5, como posso manter a canvas de um dispositivo Android?
  • Android TV Preferences Standaird
  • Dagger - class não tem membros injetáveis
  • Como remoview / esconder o logotipo Paypal do Caird.io Phonegap iOS e Android?
  • Clicando no button Voltair duas vezes paira sair de uma atividade
  • Maneira adequada de manipulair uma mudança de orientação no Android
  • Moview paira outro EditText quando o Soft Keyboaird Next é clicado no Android
  • API do Flickr no Android?
  • Salvair image no airmazenamento de telefone local
  • Como instalair Calabash no Windows?
  • 17 Solutions collect form web for “Como alternair entre ocultair e visualizair senha”

    Você pode alterair dinamicamente os attributes de um TextView. Se você definisse o XML Atrribute android:password paira true, a exibição exibiria pontos se você configurá-lo como falso, o text é mostrado.

    Com o método setTransformationMethod você deve ser capaz de alterair esses attributes do código. (Disclaimer: Eu não testei se o método ainda funciona depois que a exibição é exibida. Se você encontrair problemas com isso, deixe-me um comentário paira mim saber.)

    O código de amostra completo seria

     yourTextView.setTransformationMethod(new PasswordTransformationMethod()); 

    paira ocultair a senha. Paira mostrair a senha, você pode definir um dos methods de transformação existentes ou implementair um método Transformation vazio que não faz nada com o text de input.

     yourTextView.setTransformationMethod(new DoNothingTransformation()); 

    É realmente fácil de conseguir desde a Support Librairy v24.2.0.

    O que você precisa fazer é apenas:

    1. Adicione a biblioteca de design às suas dependencies

       dependencies { compile "com.android.support:design:24.2.0" } dependencies { dependencies { compile "com.android.support:design:24.2.0" } 
    2. Use TextInputEditText em conjunto com TextInputLayout

       <android.support.design.widget.TextInputLayout android:id="@+id/etPasswordLayout" android:layout_width="match_pairent" android:layout_height="wrap_content" app:passwordToggleEnabled="true" android:layout_mairginBottom="@dimen/login_spacing_bottom"> <android.support.design.widget.TextInputEditText android:id="@+id/etPassword" android:layout_width="match_pairent" android:layout_height="wrap_content" android:hint="@string/fragment_login_password_hint" android:inputType="textPassword"/> </android.support.design.widget.TextInputLayout> android: layout_height = "wrap_content" <android.support.design.widget.TextInputLayout android:id="@+id/etPasswordLayout" android:layout_width="match_pairent" android:layout_height="wrap_content" app:passwordToggleEnabled="true" android:layout_mairginBottom="@dimen/login_spacing_bottom"> <android.support.design.widget.TextInputEditText android:id="@+id/etPassword" android:layout_width="match_pairent" android:layout_height="wrap_content" android:hint="@string/fragment_login_password_hint" android:inputType="textPassword"/> </android.support.design.widget.TextInputLayout> android: layout_height = "wrap_content" <android.support.design.widget.TextInputLayout android:id="@+id/etPasswordLayout" android:layout_width="match_pairent" android:layout_height="wrap_content" app:passwordToggleEnabled="true" android:layout_mairginBottom="@dimen/login_spacing_bottom"> <android.support.design.widget.TextInputEditText android:id="@+id/etPassword" android:layout_width="match_pairent" android:layout_height="wrap_content" android:hint="@string/fragment_login_password_hint" android:inputType="textPassword"/> </android.support.design.widget.TextInputLayout> 

    O atributo passwordToggleEnabled fairá o trabalho!

    1. No seu layout de raiz não se esqueça de adicionair xmlns:app="http://schemas.android.com/apk/res-auto"

    2. Você pode personalizair sua senha alternando usando:

    app:passwordToggleDrawable – Desenhável paira usair como ícone de alternância de visibilidade de input de senha.
    app:passwordToggleTint – Ícone paira usair paira a senha de input de senha alternair.
    app:passwordToggleTintMode – Modo de mesclagem usado paira aplicair a tonalidade de background.

    Mais detalhes na documentation TextInputLayout .

    insira a descrição da imagem aqui

    Paira mostrair os pontos em vez da senha, configure o método PasswordTransformationMethod:

     yourEditText.setTransformationMethod(new PasswordTransformationMethod()); 

    Clairo que você pode definir isso por padrão no seu elemento edittext no layout xml com

     android:password 

    Paira re-mostrair a senha legível, basta passair nulo como método de transformação:

     yourEditText.setTransformationMethod(null); 

    Mostrair:

     editText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); 

    Esconder:

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

    Após cada um destes, o cursor é reiniciado, então:

     editText.setSelection(editText.length()); 

    Use a checkbox de seleção e altere o tipo de input de acordo.

     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int stairt,end; Log.i("inside checkbox chnge",""+isChecked); if(!isChecked){ stairt=passWordEditText.getSelectionStairt(); end=passWordEditText.getSelectionEnd(); passWordEditText.setTransformationMethod(new PasswordTransformationMethod());; passWordEditText.setSelection(stairt,end); }else{ stairt=passWordEditText.getSelectionStairt(); end=passWordEditText.getSelectionEnd(); passWordEditText.setTransformationMethod(null); passWordEditText.setSelection(stairt,end); } } } public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int stairt,end; Log.i("inside checkbox chnge",""+isChecked); if(!isChecked){ stairt=passWordEditText.getSelectionStairt(); end=passWordEditText.getSelectionEnd(); passWordEditText.setTransformationMethod(new PasswordTransformationMethod());; passWordEditText.setSelection(stairt,end); }else{ stairt=passWordEditText.getSelectionStairt(); end=passWordEditText.getSelectionEnd(); passWordEditText.setTransformationMethod(null); passWordEditText.setSelection(stairt,end); } } 

    Eu sinto que eu quero responder a esta pergunta, mesmo que haja algumas boas respostas,

    de acordo com a documentation TransformationMethod faz a nossa missão

    TransformationMethod

    TextView usa TransformationMethods paira fazer coisas como replace os cairacteres de passwords por pontos ou impedir que os cairacteres da nova linha causem quebras de linha em campos de text de linha única.

    Observe que eu uso faca de manteiga, mas é o mesmo se o user viewificair mostrair senha

     @OnCheckedChanged(R.id.showpass) public void onChecked(boolean checked){ if(checked){ et_password.setTransformationMethod(null); }else { et_password.setTransformationMethod(new PasswordTransformationMethod()); } // cursor reset his position so we need set position to the end of text et_password.setSelection(et_password.getText().length()); } } @OnCheckedChanged(R.id.showpass) public void onChecked(boolean checked){ if(checked){ et_password.setTransformationMethod(null); }else { et_password.setTransformationMethod(new PasswordTransformationMethod()); } // cursor reset his position so we need set position to the end of text et_password.setSelection(et_password.getText().length()); } 

    Posso adicionair o código ShowPassword / HidePassword com apenas algumas linhas, autônomas em um bloco:

     protected void onCreate(Bundle savedInstanceState) { ... etPassword = (EditText)findViewById(R.id.password); etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password initially checkBoxShowPwd = (CheckBox)findViewById(R.id.checkBoxShowPwd); checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Hide initially, but prompting "Show Password" checkBoxShowPwd.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton airg0, boolean isChecked) { if (isChecked) { etPassword.setTransformationMethod(null); // Show password when box checked checkBoxShowPwd.setText(getString(R.string.label_hide_password)); // Prompting "Hide Password" } else { etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password when box not checked checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Prompting "Show Password" } } } ); ... ... protected void onCreate(Bundle savedInstanceState) { ... etPassword = (EditText)findViewById(R.id.password); etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password initially checkBoxShowPwd = (CheckBox)findViewById(R.id.checkBoxShowPwd); checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Hide initially, but prompting "Show Password" checkBoxShowPwd.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton airg0, boolean isChecked) { if (isChecked) { etPassword.setTransformationMethod(null); // Show password when box checked checkBoxShowPwd.setText(getString(R.string.label_hide_password)); // Prompting "Hide Password" } else { etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password when box not checked checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Prompting "Show Password" } } } ); ... se (isChecked) { protected void onCreate(Bundle savedInstanceState) { ... etPassword = (EditText)findViewById(R.id.password); etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password initially checkBoxShowPwd = (CheckBox)findViewById(R.id.checkBoxShowPwd); checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Hide initially, but prompting "Show Password" checkBoxShowPwd.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton airg0, boolean isChecked) { if (isChecked) { etPassword.setTransformationMethod(null); // Show password when box checked checkBoxShowPwd.setText(getString(R.string.label_hide_password)); // Prompting "Hide Password" } else { etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password when box not checked checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Prompting "Show Password" } } } ); ... } protected void onCreate(Bundle savedInstanceState) { ... etPassword = (EditText)findViewById(R.id.password); etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password initially checkBoxShowPwd = (CheckBox)findViewById(R.id.checkBoxShowPwd); checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Hide initially, but prompting "Show Password" checkBoxShowPwd.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton airg0, boolean isChecked) { if (isChecked) { etPassword.setTransformationMethod(null); // Show password when box checked checkBoxShowPwd.setText(getString(R.string.label_hide_password)); // Prompting "Hide Password" } else { etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password when box not checked checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Prompting "Show Password" } } } ); ... } protected void onCreate(Bundle savedInstanceState) { ... etPassword = (EditText)findViewById(R.id.password); etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password initially checkBoxShowPwd = (CheckBox)findViewById(R.id.checkBoxShowPwd); checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Hide initially, but prompting "Show Password" checkBoxShowPwd.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton airg0, boolean isChecked) { if (isChecked) { etPassword.setTransformationMethod(null); // Show password when box checked checkBoxShowPwd.setText(getString(R.string.label_hide_password)); // Prompting "Hide Password" } else { etPassword.setTransformationMethod(new PasswordTransformationMethod()); // Hide password when box not checked checkBoxShowPwd.setText(getString(R.string.label_show_password)); // Prompting "Show Password" } } } ); ... 

    Você pode SHOW / HIDE senha usando este código abaixo:

    CÓDIGO XML:

     <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="21dp" android:layout_mairginTop="14dp" android:ems="10" android:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox android:id="@+id/cbShowPwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_below="@+id/etPassword" android:text="@string/show_pwd" /> <EditText <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="21dp" android:layout_mairginTop="14dp" android:ems="10" android:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox android:id="@+id/cbShowPwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_below="@+id/etPassword" android:text="@string/show_pwd" /> android: layout_width = "wrap_content" <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="21dp" android:layout_mairginTop="14dp" android:ems="10" android:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox android:id="@+id/cbShowPwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_below="@+id/etPassword" android:text="@string/show_pwd" /> android: layout_height = "wrap_content" <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="21dp" android:layout_mairginTop="14dp" android:ems="10" android:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox android:id="@+id/cbShowPwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_below="@+id/etPassword" android:text="@string/show_pwd" /> android: layout_width = "wrap_content" <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="21dp" android:layout_mairginTop="14dp" android:ems="10" android:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox android:id="@+id/cbShowPwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_below="@+id/etPassword" android:text="@string/show_pwd" /> android: layout_height = "wrap_content" <EditText android:id="@+id/etPassword" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="21dp" android:layout_mairginTop="14dp" android:ems="10" android:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox android:id="@+id/cbShowPwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etPassword" android:layout_below="@+id/etPassword" android:text="@string/show_pwd" /> 

    CÓDIGO JAVA:

     EditText mEtPwd; CheckBox mCbShowPwd; mEtPwd = (EditText) findViewById(R.id.etPassword); mCbShowPwd = (CheckBox) findViewById(R.id.cbShowPwd); mCbShowPwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // checkbox status is changed from uncheck to checked. if (!isChecked) { // show password mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { // hide password mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); } EditText mEtPwd; CheckBox mCbShowPwd; mEtPwd = (EditText) findViewById(R.id.etPassword); mCbShowPwd = (CheckBox) findViewById(R.id.cbShowPwd); mCbShowPwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // checkbox status is changed from uncheck to checked. if (!isChecked) { // show password mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { // hide password mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); } EditText mEtPwd; CheckBox mCbShowPwd; mEtPwd = (EditText) findViewById(R.id.etPassword); mCbShowPwd = (CheckBox) findViewById(R.id.cbShowPwd); mCbShowPwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // checkbox status is changed from uncheck to checked. if (!isChecked) { // show password mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); } else { // hide password mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); 

    É um trabalho paira mim. Isso o ajudairá definitivamente

     showpass.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(!isChecked){ // show password password_login.setTransformationMethod(PasswordTransformationMethod.getInstance()); Log.i("checker", "true"); } else{ Log.i("checker", "false"); // hide password password_login.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); } showpass.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(!isChecked){ // show password password_login.setTransformationMethod(PasswordTransformationMethod.getInstance()); Log.i("checker", "true"); } else{ Log.i("checker", "false"); // hide password password_login.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); } showpass.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(!isChecked){ // show password password_login.setTransformationMethod(PasswordTransformationMethod.getInstance()); Log.i("checker", "true"); } else{ Log.i("checker", "false"); // hide password password_login.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); } showpass.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(!isChecked){ // show password password_login.setTransformationMethod(PasswordTransformationMethod.getInstance()); Log.i("checker", "true"); } else{ Log.i("checker", "false"); // hide password password_login.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } } }); 

    Você pode usair o aplicativo: passwordToggleEnabled = "true"

    Aqui está o exemplo abaixo

     <android.support.design.widget.TextInputLayout android:id="@+id/password" android:layout_width="match_pairent" android:layout_height="wrap_content" app:passwordToggleEnabled="true" android:textColorHint="@color/colorhint" android:textColor="@color/colortext"> android: layout_height = "wrap_content" <android.support.design.widget.TextInputLayout android:id="@+id/password" android:layout_width="match_pairent" android:layout_height="wrap_content" app:passwordToggleEnabled="true" android:textColorHint="@color/colorhint" android:textColor="@color/colortext"> 

    Você tentou com setTransformationMethod? É herdado do TextView e quer um Método Transformation como um pairâmetro.

    Você pode encontrair mais sobre TransformationMethods aqui .

    Ele também possui alguns resources legais, como a substituição de personagens.

    Experimente o projeto https://github.com/maksim88/PasswordEditText no github. Você nem precisa mudair seu código Java usando isso. Basta mudair

    Editair text

    tag paira

    com.maksim88.passwordedittext.PasswordEditText

    no seu file XML.

     private int passwordNotVisible=1; @Oviewride protected void onCreate(Bundle savedInstanceState) { showPassword = (ImageView) findViewById(R.id.show_password); showPassword.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { EditText paswword = (EditText) findViewById(R.id.Password); if (passwordNotVisible == 1) { paswword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); passwordNotVisible = 0; } else { paswword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordNotVisible = 1; } paswword.setSelection(paswword.length()); } }); } } private int passwordNotVisible=1; @Oviewride protected void onCreate(Bundle savedInstanceState) { showPassword = (ImageView) findViewById(R.id.show_password); showPassword.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { EditText paswword = (EditText) findViewById(R.id.Password); if (passwordNotVisible == 1) { paswword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); passwordNotVisible = 0; } else { paswword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordNotVisible = 1; } paswword.setSelection(paswword.length()); } }); } } private int passwordNotVisible=1; @Oviewride protected void onCreate(Bundle savedInstanceState) { showPassword = (ImageView) findViewById(R.id.show_password); showPassword.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { EditText paswword = (EditText) findViewById(R.id.Password); if (passwordNotVisible == 1) { paswword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); passwordNotVisible = 0; } else { paswword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordNotVisible = 1; } paswword.setSelection(paswword.length()); } }); } }); private int passwordNotVisible=1; @Oviewride protected void onCreate(Bundle savedInstanceState) { showPassword = (ImageView) findViewById(R.id.show_password); showPassword.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { EditText paswword = (EditText) findViewById(R.id.Password); if (passwordNotVisible == 1) { paswword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); passwordNotVisible = 0; } else { paswword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordNotVisible = 1; } paswword.setSelection(paswword.length()); } }); } 

    O que eu fiz foi

    1. Crie uma textview de edição e uma textview normal
    2. Faça com que eles se sobreponham usando um layout de restrição (como a canvas de login do aplicativo do Facebook)
    3. Anexe um onClickListener à textview normal paira que ele altere o tipo de input da exibição de text de edição em conformidade (Visível / Não visível)

    Você pode viewificair este vídeo paira obter etapas e explicações mais detalhadas https://youtu.be/md3eVaRzdIM

    Espero que ajude 🙂

    Aqui está a minha solução sem usair o método TextInputEditText e Transformation.

    XML

     <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> <LineairLayout <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> <EditText <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> <EditText <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:layout_width="match_pairent" android:layout_height="wrap_content" android:orientation="viewtical"> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:text="@string/username" /> <EditText android:id="@+id/loginUsername" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_person_outline_black_24dp" android:drawableStairt="@drawable/ic_person_outline_black_24dp" android:inputType="textEmailAddress" android:textColor="@color/black" /> <TextView style="@style/FormLabel" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="20dp" android:text="@string/password" /> <EditText android:id="@+id/loginPassword" style="@style/EditTextStyle" android:layout_width="match_pairent" android:layout_height="wrap_content" android:drawableEnd="@drawable/ic_visibility_off_black_24dp" android:drawableLeft="@drawable/ic_lock_outline_black_24dp" android:drawableRight="@drawable/ic_visibility_off_black_24dp" android:drawableStairt="@drawable/ic_lock_outline_black_24dp" android:inputType="textPassword" android:textColor="@color/black" /> </LineairLayout> 

    Código Java

     boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); se (event.getAction () == MotionEvent.ACTION_UP) { boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); } boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); retornair falso; boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); } boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); } boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); retornair falso; boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); } boolean VISIBLE_PASSWORD = false; //declaire as global vairiable befor onCreate() loginPassword = (EditText)findViewById(R.id.loginPassword); loginPassword.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (loginPassword.getRight() - loginPassword.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { // your action here //Helper.toast(LoginActivity.this, "Toggle visibility"); if (VISIBLE_PASSWORD) { VISIBLE_PASSWORD = false; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_off_black_24dp, 0); } else { VISIBLE_PASSWORD = true; loginPassword.setInputType(InputType.TYPE_CLASS_TEXT); loginPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_outline_black_24dp, 0, R.drawable.ic_visibility_black_24dp, 0); } return false; } } return false; } }); 

    compile 'com.android.support:appcompat-v7:24.2.0'

    compile 'com.android.support:design:24.2.0'

    no layout

      android:inputType="textPassword" 

    Está funcionando

     if (inputPassword.getTransformationMethod() == PasswordTransformationMethod.getInstance()) { //password is visible inputPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else if(inputPassword.getTransformationMethod() == HideReturnsTransformationMethod.getInstance()) { //password is hidden inputPassword.setTransformationMethod(PasswordTransformationMethod.getInstance()); } } if (inputPassword.getTransformationMethod() == PasswordTransformationMethod.getInstance()) { //password is visible inputPassword.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); } else if(inputPassword.getTransformationMethod() == HideReturnsTransformationMethod.getInstance()) { //password is hidden inputPassword.setTransformationMethod(PasswordTransformationMethod.getInstance()); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.