提醒对话框和页面跳转

提醒对话框和页面跳转,第1张

概述主页面<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:app="http://schemas.android.com/apkes-auto"xmlns:tools="http://schem

主页面

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"    tools:context=".MainActivity">    <FrameLayout        androID:ID="@+ID/content"        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:layout_weight="0">    </FrameLayout>    <RadioGroup        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_margintop="40dp"        androID:orIEntation="horizontal">    <Radiobutton        androID:ID="@+ID/rb_1"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_weight="1"        androID:textSize="15dp"        androID:textcolor="#8E8433"        androID:layout_marginleft="20dp"        androID:text="密码登录"        />        <Radiobutton            androID:ID="@+ID/rb_2"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:textcolor="#8E8433"            androID:textSize="15dp"            androID:layout_marginRight="20dp"            androID:text="验证码登录"            androID:onClick="jumpToMainActivity2"            />    </RadioGroup>    <linearLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_margintop="40dp"        androID:gravity="center_vertical"        >        <TextVIEw            androID:layout_wIDth="90dp"            androID:layout_height="wrap_content"            androID:text="账号:"            androID:textcolor="#D30F64"            androID:textSize="25sp"            />        <EditText            androID:ID="@+ID/et_account"            androID:layout_wIDth="269dp"            androID:layout_height="50dp"            androID:layout_marginleft="10dp"            androID:background="@drawable/edit_text_bg"            androID:hint="请输入手机号或用户名"            androID:inputType="text"            androID:paddingleft="5dp"            androID:textSize="18sp" />    </linearLayout>    <linearLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_margintop="40dp"        androID:gravity="center_vertical"        >        <TextVIEw            androID:layout_wIDth="90dp"            androID:layout_height="wrap_content"            androID:textcolor="#D30F64"            androID:text="密码:"            androID:textSize="25sp"            />        <EditText            androID:ID="@+ID/et_password"            androID:layout_wIDth="180dp"            androID:layout_height="50dp"            androID:layout_marginleft="10dp"            androID:background="@drawable/edit_text_bg"            androID:hint="请输入密码"            androID:inputType="numberPassword"            androID:paddingleft="5dp"            androID:textSize="18sp" />        <button            androID:layout_wIDth="match_parent"            androID:layout_height="50dp"            androID:text="忘记密码"            androID:textSize="13dp"            androID:onClick="jumpToMainActivity3"            />    </linearLayout>    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:gravity="center"        androID:layout_margintop="20dp"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        >        <CheckBox            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="记住密码" />        <CheckBox            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="自动登录"            androID:layout_marginleft="40dp"            />    </linearLayout>    <button        androID:ID="@+ID/btn_Login"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="登录"        androID:textSize="25sp"        /></linearLayout>

手机验证码页面

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"    tools:context=".MainActivity2">    <RadioGroup        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:layout_margintop="40dp"        androID:orIEntation="horizontal">        <Radiobutton            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:textSize="15dp"            androID:textcolor="#8E8433"            androID:layout_marginleft="20dp"            androID:text="密码登录"            androID:onClick="jumpToMainActivity"            />        <Radiobutton            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_weight="1"            androID:textSize="15dp"            androID:textcolor="#8E8433"            androID:layout_marginRight="20dp"            androID:text="验证码登录"/>    </RadioGroup>    <linearLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_margintop="40dp"        androID:gravity="center_vertical"        >        <TextVIEw            androID:layout_wIDth="100dp"            androID:layout_height="wrap_content"            androID:text="手机号码:"            androID:textcolor="#D30F64"            androID:textSize="20sp"            />        <EditText            androID:ID="@+ID/et_phone"            androID:layout_wIDth="250dp"            androID:layout_height="50dp"            androID:layout_marginleft="10dp"            androID:background="@drawable/edit_text_bg"            androID:hint="请输入11位数手机号"            androID:inputType="number"            androID:paddingleft="5dp"            androID:textSize="18sp" />    </linearLayout>    <linearLayout        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_margintop="40dp"        androID:gravity="center_vertical"        >        <TextVIEw            androID:layout_wIDth="100dp"            androID:layout_height="wrap_content"            androID:text="验证码:"            androID:textcolor="#D30F64"            androID:textSize="20dp"            />        <EditText            androID:ID="@+ID/et_confirm"            androID:layout_wIDth="180dp"            androID:layout_height="50dp"            androID:layout_marginleft="10dp"            androID:background="@drawable/edit_text_bg"            androID:hint="请输入验证码"            androID:inputType="number"            androID:paddingleft="5dp"            androID:textSize="18sp" />        <button            androID:ID="@+ID/btn_getNum"            androID:layout_wIDth="match_parent"            androID:layout_height="50dp"            androID:text="获取验证码"            androID:textSize="11dp"            androID:onClick="jumpToAlertDialogActivity"            />    </linearLayout>    <linearLayout        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:orIEntation="horizontal"        androID:gravity="center"        androID:layout_margintop="20dp"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        >        <CheckBox            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="记住密码" />        <CheckBox            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:text="自动登录"            androID:layout_marginleft="40dp"            />    </linearLayout>    <button        androID:ID="@+ID/btn_Login1"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="登录"        androID:textSize="25sp"        /></linearLayout>

找回密码页面

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"    androID:padding="5dp" >    <relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="50dp" >        <TextVIEw            androID:ID="@+ID/tv_password_first"            androID:layout_wIDth="wrap_content"            androID:layout_height="match_parent"            androID:gravity="center"            androID:text="输入新密码:"            androID:textcolor="@color/black"            androID:textSize="17sp" />        <EditText            androID:ID="@+ID/et_password_first"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:layout_marginBottom="5dp"            androID:layout_margintop="5dp"            androID:layout_toRightOf="@+ID/tv_password_first"            androID:gravity="left|center"            androID:hint="请输入新密码"            androID:inputType="numberPassword"            androID:maxLength="11"            androID:textcolor="@color/black"            androID:textSize="17sp" />    </relativeLayout>    <relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="50dp" >        <TextVIEw            androID:ID="@+ID/tv_password_second"            androID:layout_wIDth="wrap_content"            androID:layout_height="match_parent"            androID:gravity="center"            androID:text="确认新密码:"            androID:textcolor="@color/black"            androID:textSize="17sp" />        <EditText            androID:ID="@+ID/et_password_second"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:layout_marginBottom="5dp"            androID:layout_margintop="5dp"            androID:layout_toRightOf="@+ID/tv_password_second"            androID:gravity="left|center"            androID:hint="请再次输入新密码"            androID:inputType="numberPassword"            androID:maxLength="11"            androID:textcolor="@color/black"            androID:textSize="17sp" />    </relativeLayout>    <relativeLayout        androID:layout_wIDth="match_parent"        androID:layout_height="50dp" >        <TextVIEw            androID:ID="@+ID/tv_verifycode"            androID:layout_wIDth="wrap_content"            androID:layout_height="match_parent"            androID:gravity="center"            androID:text="  验证码:"            androID:textcolor="@color/black"            androID:textSize="17sp" />        <relativeLayout            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:layout_toRightOf="@+ID/tv_verifycode" >            <EditText                androID:ID="@+ID/et_verifycode"                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent"                androID:layout_marginBottom="5dp"                androID:layout_margintop="5dp"                androID:gravity="left|center"                androID:hint="请输入验证码"                androID:inputType="number"                androID:maxLength="6"                androID:textcolor="@color/black"                androID:textSize="17sp" />            <button                androID:ID="@+ID/btn_verifycode"                androID:layout_wIDth="wrap_content"                androID:layout_height="match_parent"                androID:layout_alignParentRight="true"                androID:layout_marginRight="-3dp"                androID:gravity="center"                androID:text="获取验证码"                androID:textcolor="@color/black"                androID:textSize="17sp" />        </relativeLayout>    </relativeLayout>    <button        androID:ID="@+ID/btn_confirm"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:text="确  定"        androID:textcolor="@color/black"        androID:textSize="20sp" /></linearLayout>

MainActivity

package com.example.retrIEvepassword;import androIDx.appcompat.app.AppCompatActivity;import androIDx.fragment.app.FragmentActivity;import androID.app.AlertDialog;import androID.content.Intent;import androID.os.Bundle;import androID.text.TextUtils;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Toast;import java.util.Random;public class MainActivity extends AppCompatActivity implements VIEw.OnClickListener {    private static final String TAG = "tag";    private button btnLogin;    private EditText etAccount, etPassword;    String newPass,MPhone;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        getSupportActionbar().setTitle("用户名登录");        btnLogin = findVIEwByID(R.ID.btn_Login);        etAccount = findVIEwByID(R.ID.et_account);        etPassword = findVIEwByID(R.ID.et_password);        etAccount = findVIEwByID(R.ID.et_account);        btnLogin.setonClickListener(this);        newPass = getIntent().getStringExtra("new_password");        MPhone = getIntent().getStringExtra("phone");        Log.d(TAG, "onCreate: --------------"+newPass);        Log.d(TAG, "onCreate: --------------"+MPhone);    }    @OverrIDe    public voID onClick(VIEw v) {        String Account = etAccount.getText().toString();        String Pass = etPassword.getText().toString();        if(!Account.equals(MPhone)){            Toast.makeText(this, "用户名错误" , Toast.LENGTH_SHORT).show();        }else if(!Pass.equals(newPass)){            Toast.makeText(this, "新密码错误" , Toast.LENGTH_SHORT).show();        }        else {            Toast.makeText(this, "恭喜您!登陆成功" , Toast.LENGTH_SHORT).show();        }    }        public voID jumpToMainActivity2 (VIEw vIEw){            Intent intent = new Intent(this, MainActivity2.class);            startActivity(intent);        }        public voID jumpToMainActivity3 (VIEw vIEw){            String s = etAccount.getText().toString().trim();            Intent intent = new Intent(this, LoginForgetActivity.class);            intent.putExtra("phone", s);            startActivity(intent);        }}

验证码的Activity

package com.example.retrIEvepassword;import androIDx.appcompat.app.AppCompatActivity;import androID.content.Intent;import androID.os.Bundle;import androID.text.Editable;import androID.text.TextUtils;import androID.text.TextWatcher;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Toast;import com.example.retrIEvepassword.util.VIEwUtil;public class MainActivity2 extends AppCompatActivity implements VIEw.OnClickListener {    private static final String TAG = "tag";    private String confirm;    private EditText et_verConfirm,etPhone;    private button btnLogin;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main2);        getSupportActionbar().setTitle("验证码登录");        Intent intent = getIntent();        btnLogin = findVIEwByID(R.ID.btn_Login1);        etPhone = findVIEwByID(R.ID.et_phone);        et_verConfirm = findVIEwByID(R.ID.et_confirm);        if(intent != null){            confirm = intent.getStringExtra("data");            Log.d(TAG, "onCreate :----------------"+confirm);        }        // 给手机号码编辑框添加文本变化监听器        etPhone.addTextChangedListener(new MainActivity2.HIDeTextWatcher(etPhone, 11));        btnLogin.setonClickListener(this);    }    @OverrIDe    public voID onClick(VIEw v) {        String con = et_verConfirm.getText().toString();        String mPhone = etPhone.getText().toString();        if(mPhone != null && TextUtils.equals(con,confirm)){            Toast.makeText(MainActivity2.this,"恭喜您!登陆成功",Toast.LENGTH_LONG).show();        }else {            Toast.makeText(MainActivity2.this,"验证码错误!",Toast.LENGTH_LONG).show();        }    }    public voID jumpToAlertDialogActivity(VIEw vIEw) {        Intent intent = new Intent(this,AlertDialogActivity.class);        startActivity(intent);    }    private class HIDeTextWatcher implements TextWatcher {        private EditText mVIEw; // 声明一个编辑框对象        private int mMaxLength; // 声明一个最大长度变量        public HIDeTextWatcher(EditText v, int maxLength) {            super();            mVIEw = v;            mMaxLength = maxLength;        }        // 在编辑框的输入文本变化前触发        public voID beforeTextChanged(CharSequence s, int start, int count, int after) {}        // 在编辑框的输入文本变化时触发        public voID onTextChanged(CharSequence s, int start, int before, int count) {}        // 在编辑框的输入文本变化后触发        public voID afterTextChanged(Editable s) {            String str = s.toString(); // 获得已输入的文本字符串            // 输入文本达到11位(如手机号码),或者达到6位(如登录密码)时关闭输入法            if ((str.length() == 11 && mMaxLength == 11)) {                VIEwUtil.hIDeOneinputMethod(MainActivity2.this, mVIEw); // 隐藏输入法软键盘            }        }    }    public voID jumpToMainActivity(VIEw vIEw) {        Intent intent = new Intent(this,MainActivity.class);        startActivity(intent);    }}

忘记密码的Activity

package com.example.retrIEvepassword;import androIDx.appcompat.app.AppCompatActivity;import androID.app.Activity;import androID.app.AlertDialog;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.EditText;import androID.Widget.Toast;import java.util.Random;public class LoginForgetActivity extends AppCompatActivity implements VIEw.OnClickListener {    private EditText et_password_first; // 声明一个编辑框对象    private EditText et_password_second; // 声明一个编辑框对象    private EditText et_verifyCode; // 声明一个编辑框对象    private String mVerifyCode; // 验证码    private String mPhone; // 手机号码    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_login_forget);        // 从布局文件中获取名叫et_password_first的编辑框        getSupportActionbar().setTitle("找回密码");        et_password_first = findVIEwByID(R.ID.et_password_first);        // 从布局文件中获取名叫et_password_second的编辑框        et_password_second = findVIEwByID(R.ID.et_password_second);        // 从布局文件中获取名叫et_verifycode的编辑框        et_verifyCode = findVIEwByID(R.ID.et_verifycode);        findVIEwByID(R.ID.btn_verifycode).setonClickListener(this);        findVIEwByID(R.ID.btn_confirm).setonClickListener(this);        // 从上一个页面获取要修改密码的手机号码        mPhone = getIntent().getStringExtra("phone");    }    @OverrIDe    public voID onClick(VIEw v) {        if (v.getID() == R.ID.btn_verifycode) { // 点击了“获取验证码”按钮            if (mPhone == null || mPhone.length() < 11) {                Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();                return;            }            // 生成六位随机数字的验证码            mVerifyCode = String.format("%06d", new Random().nextInt(999999));            // 以下d出提醒对话框,提示用户记住六位验证码数字            AlertDialog.Builder builder = new AlertDialog.Builder(this);            builder.setTitle("请记住验证码");            builder.setMessage("手机号" + mPhone + ",本次验证码是" + mVerifyCode + ",请输入验证码");            builder.setPositivebutton("好的", null);            AlertDialog alert = builder.create();            alert.show(); // 显示提醒对话框        } else if (v.getID() == R.ID.btn_confirm) { // 点击了“确定”按钮            String password_first = et_password_first.getText().toString();            String password_second = et_password_second.getText().toString();            if (password_first.length() < 6 || password_second.length() < 6) {                Toast.makeText(this, "请输入正确的新密码", Toast.LENGTH_SHORT).show();                return;            }            if (!password_first.equals(password_second)) {                Toast.makeText(this, "两次输入的新密码不一致", Toast.LENGTH_SHORT).show();                return;            }            if (!et_verifyCode.getText().toString().equals(mVerifyCode)) {                Toast.makeText(this, "请输入正确的验证码", Toast.LENGTH_SHORT).show();            } else {                Toast.makeText(this, "密码修改成功", Toast.LENGTH_SHORT).show();                // 以下把修改好的新密码返回给上一个页面                Intent intent = new Intent(this,MainActivity.class); // 创建一个新意图                intent.putExtra("new_password", password_first); // 存入新密码                intent.putExtra("phone",mPhone);                startActivity(intent);            }        }    }}

总结

以上是内存溢出为你收集整理的提醒对话框和页面跳转全部内容,希望文章能够帮你解决提醒对话框和页面跳转所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1003181.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存