In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces Android how to achieve the small function of remembering passwords, which is very detailed and has a certain reference value. Friends who are interested must read it!
The details are as follows
There are three points below: the first point is to remember the password, the second point is to click hide and click display, and the third point is to log in and store.
XML layout
Java code
Package com.wd.health.v;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.text.method.HideReturnsTransformationMethod;import android.text.method.PasswordTransformationMethod;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditText;import android.widget.ImageView;import android.widget.Toast;import com.wd.health.R;import com.wd.health.base.BaseActivity;import com.wd.health.bean.LoginBean;import com.wd.health.contract.ILoginContract Import com.wd.health.net.RsaCoder;import com.wd.health.p.LoginPresenter;import butterknife.BindView;import butterknife.ButterKnife;public class MainActivity extends BaseActivity implements ILoginContract.ILoginView {@ BindView (R.id.can) ImageView can; @ BindView (R.id.ji) CheckBox ji; @ BindView (R.id.deng) Button deng; @ BindView (R.id.youxiang) EditText youxiang; @ BindView (R.id.mima) EditText mima; boolean sb=true Private SharedPreferences user; private SharedPreferences.Editor edit; @ Override protected int initView () {return R.layout.activitymains;} @ Override protected LoginPresenter CreatPresenter () {return new LoginPresenter ();} @ Override protected void loadData () {ButterKnife.bind (this); / / Hidden mima.setTransformationMethod (PasswordTransformationMethod.getInstance ()) by default / Click the small eye can.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (sb) {can.setImageResource (R.mipmap.login_icon_show_password); mima.setTransformationMethod (HideReturnsTransformationMethod.getInstance ()); / / display sb=false } else {can.setImageResource (R.mipmap.login_icon_hide_password_n); mima.setTransformationMethod (PasswordTransformationMethod.getInstance ()); / / hide sb=true;}); / / remember the password user = getSharedPreferences ("user", MODE_PRIVATE) Boolean isRemenber = user.getBoolean ("remember_password", false); if (isRemenber) {youxiang.setText (user.getString ("phone", ")); mima.setText (user.getString (" password ",")); ji.setChecked (true) } / / Click to log in to deng.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {String S1 = youxiang.getText () .toString (); / / get the input box mailbox String S2 = mima.getText () .toString () / / get the input box password String a = ""; / / store the encrypted password try {a = RsaCoder.encryptByPublicKey (S2); / / encrypted password} catch (Exception e) {e.printStackTrace () } if (s1.equals (")) {/ / if the mailbox is empty, toast Toast.makeText (MainActivity.this," Please enter mailbox ", Toast.LENGTH_SHORT) .show () } else if (s2.equals (")) {/ / if the password is empty, toast Toast.makeText (MainActivity.this," Please enter password ", Toast.LENGTH_SHORT). Show ();} else {/ / this is the P-layer mPresenter.ShowDengPresenter called by MVP (S1 mPresenter.ShowDengPresenter) / / S1 is the mailbox an is the encrypted password / / remember the password edit = user.edit (); if (ji.isChecked ()) {edit.putBoolean ("remember_password", true); edit.putString ("phone", S1) / / No encrypted mailbox edit.putString ("password", S2); / / No encrypted password} else {edit.clear ();} edit.apply ();}) } @ Override public void ShowDengView (LoginBean loginBean) {Toast.makeText (this, loginBean.getMessage (), Toast.LENGTH_SHORT) .show () If (loginBean.getStatus (). Equals ("0000")) {user.edit (). PutString ("userId", String.valueOf (loginBean.getResult (). GetUserId () .putString ("sessionId", loginBean.getResult (). GetSessionId ()) .putString ("nickName", loginBean.getResult (). GetNickName ()) .putString ("userName") LoginBean.getResult (). GetUserName (). PutString ("jiGuangPwd", loginBean.getResult (). GetJiGuangPwd ()) .putString ("headPic", loginBean.getResult (). GetHeadPic ()) .putString ("sex", String.valueOf (loginBean.getResult (). GetSex () .putString ("age") String.valueOf (loginBean.getResult (). GetAge ()) .putString ("height", String.valueOf (loginBean.getResult (). GetHeight () .putString ("weight", String.valueOf (loginBean.getResult (). GetWeight () .putString ("email", String.valueOf (loginBean.getResult (). GetEmail () .putString ("whetherBingWeChat") String.valueOf (loginBean.getResult (). GetWhetherBingWeChat ()) .putString ("invitationCode", String.valueOf (loginBean.getResult (). GetInvitationCode () .putString ("faceFlag", String.valueOf (loginBean.getResult (). GetFaceFlag () .commit () / / after success, jump to the home page Intent intent = new Intent (MainActivity.this,HomeActivity.class); startActivity (intent); finish ();} above is all the content of the article "how to remember passwords in Android". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.