移动技术开发:登录注册界面

1 实验名称

登录注册界面

2 实验目的

掌握基本布局管理器的使用方法和基本控件的使用方法

3 实验源代码

布局文件代码:

java 复制代码
<?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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="欢迎参加手机软件设计赛"
        android:gravity="center"
        android:textSize="24sp"
        android:textColor="#00ff00"
        />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/user"
        android:textSize="20sp"
        />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/password"
        android:textSize="20sp"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login"
        android:textSize="24sp"
        android:textColor="#00ff00"
        />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/register"
        android:textSize="24sp"
        android:textColor="#00ff00"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/test"
        android:autoLink="all"
        />

</LinearLayout>

<resources>
    <string name="app_name">CompetitionLoginDemo</string>
    <string name="user">请输入用户名</string>
    <string name="password">请输入密码</string>
    <string name="login">登录</string>
    <string name="register">注册</string>
    <string name="test">如有疑问请联系我们\n联系电话:1111111111\nE-mail:3244575757@qq.com\n网址:http//iet.jxufe.cn\n</string>

</resources>

Java代码:

java 复制代码
package com.example.competitionlogindemo;

import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    private TextView tv_title = null;//定义文本框对象

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv_title = findViewById(R.id.tv_title);
        //将布局文件中id号是tv_title的文本框跟MainActivity类中定义的成员变量tv_title对象关联到一起

        tv_title.setText(Html.fromHtml("欢迎参加<font color='red'>手机软件</font>设计赛"));

    }
}

4 实验运行结果图

5 实验总结

先写了布局文件,使用LinearLayout进行布局,先是一个文本框,"欢迎参加手机软件设计赛",使用了两种颜色;接着是两个文本编辑框,有提示词,分别输入用户名和密码;然后设置了两个按钮,登录和注册,字体设置为绿色;最后又是一个文本框,有四行文字。

写完布局文件开始写Java代码,先定义文本框对象,再将布局文件中的文本框和类中定义的成员变量对象关联到一起。

相关推荐
天诰8 分钟前
SA-K-11 检索会消失吗与四个未解问题
java·服务器·人工智能·python·机器学习·ai编程
这个昵称不容易4 小时前
SpringBoot「衣依」服装销售平台:144个Java文件180个接口,从挑衣服到收货评价整条链路都在
java·springboot·毕设
计算机毕设定制辅导-无忧学长4 小时前
《基于微信小程序的居家医疗陪护预约系统设计与实现》
java·spring boot·微信小程序·uniapp·居家医疗陪护预约系统
文丑颜不良啊5 小时前
LeetCode2221~2240题目解析
java·leetcode
秋饼6 小时前
Computer Use Agent Java 落地实战:感知-行动循环、执行器与安全围栏生产级实现
java·ai·技术分享·后端开发
文丑颜不良啊7 小时前
LeetCode2161~2180题目解析
java·leetcode
文丑颜不良啊9 小时前
LeetCode2141~2160题目解析
java·leetcode
LabVIEW开发9 小时前
LabVIEW 连接板:28 个端子怎么排,优先级怎么定
java·算法·labview
天天被压力10 小时前
【A股分钟级高频数据完全手册 #07】北交所历史分钟K线接口:京市Pro版分时批量
java·人工智能·python
天天被压力10 小时前
【A股分钟级高频数据完全手册 #08】股票日、分时数据接口对比:普通分时与Pro版差异实测
java·人工智能·python