Show and hide when Android enters a password

Source: Internet
Author: User

In the login or registration, some software, the requirements of the password can be viewed and hidden, in fact, the implementation is very simple.


First define the layout:

<linearlayout android:layout_width= "fill_parent" android:layout_height= "50.0dip" Android:layout_ma rginleft= "15dip" android:layout_marginright= "15dip" android:background= "@drawable/update_password_item_bg_bo            Ttom "android:gravity=" center_vertical "android:orientation=" Horizontal "> <textview Android:layout_width= "Wrap_content" android:layout_height= "fill_parent" android:gravity= "right|cent Er_vertical "android:paddingleft=" 5.0dip "android:text=" @string/login_pwd "Android:textco Lor= "@android: Color/black" android:textsize= "16.0sp"/> <edittext android:id= "@+id/my_l            Ottery_login_page_password "android:layout_width=" 0px "android:layout_height=" fill_parent "            android:layout_marginleft= "5.0dip" android:layout_marginright= "5.0dip" android:layout_weight= "3" Android:backgrOund= "@android: Color/white" android:hint= "@string/login_imput_pwd" android:inputtype= "Textpassword"            Android:maxlength= "android:paddingleft=" 5.0dip "android:singleline=" true "            Android:textsize= "16.0sp"/> <button android:id= "@+id/my_lottery_login_page_show_password"            Android:layout_width= "45dip" android:layout_height= "30dip" android:layout_marginright= "3dip" android:background= "@drawable/btn_yangzhengma_selector" android:text= "Display" android:textcolor= "#454545" android:textsize= "14sp"/> </LinearLayout>

Then listen to the button. In Java code, define a tag


Private Boolean Showpassword = False;if (Showpassword) {//show password   Showpassword =!showpassword;login_show_ Password.settext ("hidden"); Login_page_password.settransformationmethod (hidereturnstransformationmethod.getinstance ()); Login_page_password.setselection (Login_page_password.gettext (). toString (). Length ()); else{//hidden Password Showpassword =!showpassword;login_show_password.settext ("display"); Login_page_ Password.settransformationmethod (Passwordtransformationmethod.getinstance ()); Login_page_password.setselection ( Login_page_password.gettext (). toString (). Length ());}






Show and hide when Android enters a password

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.