您现在的位置是:群英 > 开发技术 > 移动开发
Android实现注册页面的方法和操作是什么
Admin发表于 2022-05-17 11:47:191046 次浏览
这篇文章主要给大家介绍“Android实现注册页面的方法和操作是什么”的相关知识,下文通过实际案例向大家展示操作过程,内容简单清晰,易于学习,有这方面学习需要的朋友可以参考,希望这篇“Android实现注册页面的方法和操作是什么”文章能对大家有所帮助。

安卓学习:实现注册页面输入数据,点击注册按钮跳转到另一个页面并显示输入信息

效果:

实现

1.创建安卓文件

2.创建注册界面,勾选为启动页

3.编写代码

启动界面activity_register11.xml

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bk024"
    android:gravity="center"
    android:padding="15sp"
    android:orientation="vertical"
    tools:context=".register11">

    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textcolor="#ffff00"
            android:text="@string/name"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edtname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvsex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textcolor="#ffff00"
            android:text="@string/sex"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edtsex"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textcolor="#ffff00"
            android:text="@string/age"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edtage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvphone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textcolor="#ffff00"
            android:text="@string/phone"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edtphone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvemail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textcolor="#ffff00"
            android:text="@string/email"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edtemail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvhomepage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/homepage"
            android:textcolor="#ffff00"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edthomepage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <textview
            android:id="@+id/tvremark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textcolor="#ffff00"
            android:text="@string/remark"
            android:textsize="25sp"/>
        <edittext
            android:id="@+id/edtremark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="12"
            android:singleline="true"/>
    </linearlayout>
    <linearlayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal">

        <button
            android:id="@+id/btnregister"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingleft="30dp"
            android:paddingright="30dp"
            android:background="@color/danlv"
            android:textcolor="#ffffff"
            android:text="@string/register"
            android:layout_marginright="10dp"
            android:textsize="20sp"/>

        <button
            android:id="@+id/btncancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingleft="30dp"
            android:paddingright="30dp"
            android:background="@color/danlv"
            android:text="@string/cancel"
            android:textsize="20sp"
            android:textcolor="#ffffff"/>
    </linearlayout>
</linearlayout>

register11.java

import android.content.intent;
import android.os.bundle;
import android.view.view;
import android.widget.button;
import android.widget.edittext;
import android.widget.toast;

import androidx.appcompat.app.actionbar;
import androidx.appcompat.app.appcompatactivity;

public class register11 extends appcompatactivity {
    private edittext edtname;
    private edittext edtsex;
    private edittext edtage;
    private edittext edtphone;
    private edittext edtemail;
    private edittext edthomepage;
    private edittext edtremark;
    private button btnregister;
    private button btncancel;

    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_register11);
        //活动栏图标
        actionbar actionbar = getsupportactionbar();
        actionbar.setdisplayshowhomeenabled(true);
        actionbar.setdisplayuselogoenabled(true);
        actionbar.setlogo(r.mipmap.icon);
        //获取控件实例
        edtname = findviewbyid(r.id.edtname);
        edtsex = findviewbyid(r.id.edtsex);
        edtage = findviewbyid(r.id.edtage);
        edtphone = findviewbyid(r.id.edtphone);
        edtemail = findviewbyid(r.id.edtemail);
        edthomepage = findviewbyid(r.id.edthomepage);
        edtremark = findviewbyid(r.id.edtremark);
        btnregister = findviewbyid(r.id.btnregister);
        btncancel = findviewbyid(r.id.btncancel);
        //给注册按钮注册监听器
        btnregister.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view view) {
                //保存用户输入数据
                string strname=edtname.gettext().tostring().trim();//trim()去除用户在前面输入的空格
                string strsex=edtsex.gettext().tostring().trim();
                string strage=edtage.gettext().tostring().trim();//trim()去除用户在前面输入的空格
                string strphone=edtphone.gettext().tostring().trim();//trim()去除用户在前面输入的空格
                string stremail=edtemail.gettext().tostring().trim();
                string strhomepage=edthomepage.gettext().tostring().trim();//trim()去除用户在前面输入的空格
                string strremark=edtremark.gettext().tostring().trim();

                //利用吐司提示用户注册情况
                toast.maketext(register11.this, "注册成功", toast.length_short).show();//length_short表示登录时间长度
                //创建显示意图
                intent intent = new intent(register11.this, mainactivity.class);
                //创建数据包封装数据(封装)
                bundle date = new bundle();
                date.putstring("name", strname);
                date.putstring("sex", strsex);
                date.putstring("age", strage);
                date.putstring("phone", strphone);
                date.putstring("email", stremail);
                date.putstring("homepage", strhomepage);
                date.putstring("remark", strremark);
                //通过意图携带数据包
                intent.putextras(date);
                //按照意图启动目标组件
                startactivity(intent);

            }
        });
        btncancel.setonclicklistener(new view.onclicklistener() {
            @override
            public void onclick(view view) {
                //关闭窗口
                finish();
            }
        });
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@drawable/bk028"
tools:context=".mainactivity">

<textview
    android:id="@+id/tvmessage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" "
    android:textsize="25dp"
    android:textcolor="#ff2233"
    />
</linearlayout>

activitymain.java

import android.content.intent;
import android.os.bundle;
import android.widget.textview;

import androidx.appcompat.app.appcompatactivity;

public class mainactivity extends appcompatactivity {
    protected textview tvmessage;

    @override
    protected void oncreate(bundle savedinstancestate) {
        super.oncreate(savedinstancestate);
        setcontentview(r.layout.activity_main);
        //通过资源标识符获取控件实例
        tvmessage = findviewbyid(r.id.tvmessage);
        //获取意图
        intent intent = getintent();
        //判断意图是否为空
        if (intent != null) {
            //获取意图携带数据包(封装)
            bundle date = intent.getextras();
            string name = date.getstring("name");
            string sex = date.getstring("sex");
            string age = date.getstring("age");
            string phone = date.getstring("phone");
            string email = date.getstring("email");
            string homepage = date.getstring("homepage");
            string remark = date.getstring("remark");
            //拼接用户信息
            string message = "注册成功!\n姓名:" + name + "\n性别:" + sex + "\n年龄:" + age + "\n电话:" + phone + "\n邮箱:" + email + "\n主页:" + homepage + "\n备注:" + remark;
            //设置标签属性,显示用户信息
            tvmessage.settext(message);
        }
    }
}

感谢各位的阅读,以上就是“Android实现注册页面的方法和操作是什么”的内容了,通过以上内容的阐述,相信大家对Android实现注册页面的方法和操作是什么已经有了进一步的了解,如果想要了解更多相关的内容,欢迎关注群英网络,群英网络将为大家推送更多相关知识点的文章。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

标签: 注册页面
相关信息推荐
2022-05-17 11:50:54 
摘要:​​为什么录制的MP4视频在本地可以播放但是使用html5的video多媒体播放标签不能正常播放只有一个进度条而不显示图像?其实就是一个视频编码的问题,格式虽然都是MP4但是html中只支持H.264的编码格式,无奈只能重新转换一下
2022-09-24 17:13:18 
摘要:6.0中间件分为系统中间件和应用中间件,本文就详细的介绍一下Thinkphp6.0中间件的具体使用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
2021-11-03 17:49:06 
摘要:这篇文章给大家分享的是PHP中的引用符&的内容。小编觉得挺实用的,因此分享给大家做个参考,对新手学习PHP有一定的帮助,文中示例代码介绍的非常详细,感兴趣的朋友接下来一起跟随小编看看吧。
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部