- 给退出登录添加一个监听事件
exitLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SettingActivity.this, "退出登录", Toast.LENGTH_SHORT).show();
new AlertDialog.Builder(SettingActivity.this)
.setTitle("退出")
.setMessage("确认退出登录?")
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SharedUtils.clearLoginInfo(SettingActivity.this);
// 返回我的界面
Intent intent = new Intent();
intent.putExtra("isLogin", false);
setResult(RESULT_OK, intent);
SettingActivity.this.finish();
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
});
-
修改密码效果如下
修改密码.png
<RelativeLayout
android:id="@+id/rl_modify_pwd"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#F7F8F8"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="25dp"
android:text="修改密码"
android:textColor="#A3A3A3"
android:textSize="16sp" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="25dp"
android:src="@mipmap/ic_right_arrow" />
</RelativeLayout>
- 密码的修改
if (TextUtils.isEmpty(oldPwd)) {
Toast.makeText(ModifyPwdActivity.this, "原密码不能为空", Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(newPwd) || TextUtils.isEmpty(newPwdAgain)) {
Toast.makeText(ModifyPwdActivity.this, "新密码不能为空", Toast.LENGTH_SHORT).show();
} else if (!newPwd.equals(newPwdAgain)) {
Toast.makeText(ModifyPwdActivity.this, "两次输入的新密码不一致", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ModifyPwdActivity.this, "新密码设置成功", Toast.LENGTH_SHORT).show();
SharedUtils.saveStrValue(this, username, MD5Utils.md5(newPwd));
SharedUtils.clearLoginInfo(this);
Intent intent = new Intent(ModifyPwdActivity.this, LoginActivity.class);
startActivity(intent);
ModifyPwdActivity.this.finish();
}
- 内部存储
// 1. 打开文件输出流
FileOutputStream out = this.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
// 2. 创建BufferedWriter对象
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
// 3. 写入数据
writer.write(JSON.toJSONString(userInfo));
// 4. 关闭输出流s
网友评论