android studio kotlin实现登录、注册

该博客围绕Android实验展开,要实现3 - 4个Activity跳转,包括注册、登录、好友列表页面等。需用两种以上布局设计Activity,注册界面要有8种以上基本控件并规范业务逻辑。详细介绍了登录和注册页面的实现步骤,如新建文件、设置布局、处理逻辑等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验内容:

  1. 实验实现3-4个Activity之间的跳转,包括注册页面、登录页面、好友列表页面等。实验必须使用两种以上的布局方式完成Acitivity的设计。
  2. 其中用户注册界面中需要出现8种以上的Android基本控件,并在Activity文件中对业务逻辑进行规范:如密码必须匹配,性别必须选择、年龄必须在一个合理范围内等等,当用户填写内容不正确时给出有效的提示。此界面可以做到国际化效果。可参照老师课堂上的案例。

实现好友列表界面,相应ListView中OnItemClick的点击事件。

实验步骤:

首先先新建一个项目。

1.登录页面:

(1)新建一个LoginActivity.kt文件,并在res目录的layout文件夹中创建activity_login.xml文件。有关登录页面的实现效果都在这两个文件中体现。

(2)先将布局方式改成RelativeLayout布局,如果想在页面中添加背景,可以添加android:background这个属性。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".LoginActivity">

</RelativeLayout>

(3)添加文字和样式:设置TextView和EditText的id、宽度(layout_width)、高度(layout_height)、字体大小(textSize)、文本(text)、文字的对齐方式(gravity)、控件的对齐方式(layout_gravity)等。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".LoginActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/big_login"
        android:textSize="40dp"
        android:text="登录"
        android:gravity="center"
        android:layout_gravity="center_vertical"
        android:layout_margin="30dp" />

    <!--    手机号-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Layoutstyle">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text_name"
            android:text="手机号码:"
            android:textSize="22dp" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/username"
            android:layout_marginLeft="0dp"
            android:hint="请输入手机号"
            android:textColor="@color/black"
            android:gravity="center_vertical"
            android:textSize="25dp"/>

    </LinearLayout>

        <!--    密码-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Layoutstyle">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/text_pwd"
            android:text="密\u3000\u3000码:"
            android:textSize="22dp"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pwd"
            android:hint="请输入密码"
            android:textColor="@color/black"
            android:gravity="center_vertical"
            android:inputType="textPassword"
            android:textSize="22dp"
            android:layout
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值