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
}
}
});
}
}