Android set password for plaintext and ciphertext display example

Source: Internet
Author: User

We often find in some software that there is a button behind the password input box that allows us to enter the password to display the ciphertext (or * * *), or can be displayed as a normal visible state, the effect is shown.

Specifically implemented as follows:

Layout:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:layout_margin= "15DP"
android:orientation= "Horizontal" >

    <edittext
        android:id= "@+id/et_password"
        android:layout_width= "0DP"
         android:layout_height= "50DP"
        android:layout_weight= "5 "
        android:paddingleft=" 10DP
         android:digits= "0123456789abcdefghigklmnopqrstuvwxyzQWERTYUIOPASDFGHJKLZXCVBNM"
         android:gravity= "center_vertical"
        Android:hint= "6-16-bit, number and password combination"
        android:inputtype= "Textpassword"
        android:textcolorhint= "#999999"
         android:textsize= "16sp"/>

<button
Android:id= "@+id/btn_pwd"
Android:layout_width= "0DP"
android:layout_height= "50DP"
android:layout_weight= "1"
android:gravity= "Center"
android:text= "PlainText"/>

</LinearLayout>

Mainactivity:

Package zmit.cn.edittext;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText;


public class Mainactivity extends activity {
private static final int password_mingwen = 0x90;
private static final int password_miwen = 0X81;
Private EditText EditText;
Private button button;

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
EditText = (edittext) Findviewbyid (R.id.et_password);
Button = (button) Findviewbyid (R.ID.BTN_PWD);
Button.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String str = Button.gettext (). toString (). Trim ();
if (Str.equals ("plaintext")) {
Button.settext ("ciphertext");
Edittext.setinputtype (Password_mingwen);//set to display as clear text
Edittext.setselection (Edittext.length ());//Set cursor display
else if (str.equals ("ciphertext")) {
Button.settext ("clear text");
Edittext.setinputtype (Password_miwen);//set to display as Redaction
Edittext.setselection (Edittext.length ());//Set cursor display
}
}
});
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.