昨天做完了驗證碼,那今天就把他加入到帳號密碼之中
首先要先建立一個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();
}
}
成果如下
接著帳號密碼錯誤的時候