Android学习笔记30

昨天做完了验证码,那今天就把他加入到帐号密码之中
首先要先建立一个imageview来存放验证码,并把它设置为不可见

<LinearLayout
    android:id="@+id/code"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="50dp"
    android:visibility="invisible">

    <ImageView
        android:id="@+id/identifyingcode_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

接着判断帐号密码与验证码的逻辑

if (password.getText().toString().equals(userpassword) &&
        (account.getText().toString().equals(usercellphone) ||
        account.getText().toString().equals(useremail))){
        if(code.getVisibility()==View.VISIBLE) {
            if (usercode.getText().toString().toLowerCase().equals(realCode)) {
                if(checkbox.isChecked()){
                    SharedPreferences remember = getSharedPreferences("remember", MODE_PRIVATE);
                    remember.edit().putString("account", acc).putString("password", pass).putBoolean("ischeck",true).commit();
                    Bundle bundle = new Bundle();
                    bundle.putString("page", "1");
                    start(FragmentActivity.class, bundle, true);
                }
                else{
                    SharedPreferences remember=getSharedPreferences("remember",MODE_PRIVATE);
                    remember.edit().clear().commit();
                    Bundle bundle=new Bundle();
                    bundle.putString("page","1");
                    start(FragmentActivity.class,bundle,true);
                }
            }
            else{
                Toast.makeText(this,"验证码错误",Toast.LENGTH_SHORT).show();
            }
        }
        else{
            if (checkbox.isChecked()) {
                SharedPreferences remember = getSharedPreferences("remember", MODE_PRIVATE);
                remember.edit().putString("account", acc).putString("password", pass).putBoolean("ischeck",true).commit();
                Bundle bundle = new Bundle();
                bundle.putString("page", "1");
                start(FragmentActivity.class, bundle, true);
            }
            else{
                SharedPreferences remember = getSharedPreferences("remember", MODE_PRIVATE);
                remember.edit().clear().commit();
                Bundle bundle = new Bundle();
                bundle.putString("page", "1");
                start(FragmentActivity.class, bundle, true);
            }
        }
    }
    else{
        code.setVisibility(View.VISIBLE);
        visible.setVisibility(View.VISIBLE);
        Toast.makeText(this, "帐号密码错误", Toast.LENGTH_SHORT).show();
    }

}

成果如下
https://ithelp.ithome.com.tw/upload/images/20211009/201417913bZmiuMlKS.png
接着帐号密码错误的时候
https://ithelp.ithome.com.tw/upload/images/20211009/20141791DwbnFDySn4.png


<<:  [第二十四只羊] 迷雾森林舞会XVIII 游戏角色设定again_final_final

>>:  轻松小单元 - 常见问题

<Day1> 前言

简短自我介绍 大家好!我是Marshal,目前还是一位在校大学生,就读资讯相关科系。 为什麽会想选这...

[火锅吃到饱-18] 红亭回转麻辣锅 - 台中港三井Outlet - MITSUI OUTLET PARK Taichung #老四川

昨天有提到人变成主角,食物变成配角,大概就是像这样 广义上来说,吃到饱是从红亭开始的,但是我那时候都...

DAY27 - 建议避免的CSS命名规则

昨天,提供了一种CSS命名的方法, 今天,我们再来看看有什麽要避免的CSS命名呢? 避免直接把颜色放...

【第三天 - Stack 题目分析】

先简单回顾一下,今天预计分析的题目: Valid Parentheses 昨天问到,如果 ([)] ...

Day 07 JavaScript/Rails API

阿修的说文解字 API 的全名是 Application Programming Interface...