设置界面所学知识

  • 给退出登录添加一个监听事件
  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
 
        
        
    
  • 密码的修改
 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

你可能感兴趣的:(设置界面所学知识)