移动终端应用开发上机1环境配置和用户界面设计

一、题目:界面设计。

(1)根据下图开发一个单页面的APP。
(2)“清空”按钮事件:点击清空后,所输入的文字都清空。
(3)“登陆”按钮事件:点击登陆后,对比账号和密码:如果账号和密码分别对应admin和123,则提示登陆成功;否则提示登陆失败。
界面示意图

二、界面显示

界面显示

三、代码

布局文件里的代码我用的是我们学校里教材的网格布局(老拿来主义了),也可以用其他布局。
布局文件下代码:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:useDefaultMargins="true"
    android:columnCount="4"  >

    <TextView
        android:layout_column="0"
        android:layout_row="3"
        android:layout_columnSpan="4"
        android:layout_gravity="center_horizontal"
        android:text="请输入你的账号admin与密码123"
        android:textSize="20dip" />

    <TextView
        android:text="用户名:"
        android:layout_gravity="right" />

    <EditText
        android:id="@+id/edit01"
        android:ems="8"
        android:layout_columnSpan="2"/>

    <TextView
        android:text="密码:"
        android:layout_column="0"
        android:layout_gravity="right"/>

    <EditText
        android:id="@+id/edit02"
        android:ems="8"
        android:layout_columnSpan="2" />

    <Button
        android:id="@+id/button01"
        android:text="清空"
        android:layout_column="1"
        android:layout_gravity="fill_horizontal" />

    <Button
        android:id="@+id/button02"
        android:text="登录"
        android:layout_column="2"
        android:layout_gravity="fill_horizontal" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_row="0"
        android:layout_gravity="center_horizontal"
        android:layout_column="0"
        android:layout_rowSpan="3"
        android:layout_columnSpan="4"
        app:srcCompat="@drawable/white_nights" />

</GridLayout>

程序运行的代码用到了:

  1. 调用findViewById()函数分别定位xml文件中的button(清除、登录)和输入的账号密码
  2. 设置button的监听器
  3. 调用AlertDialog()函数,设置弹窗
  4. ifelse语句判断自己输入的字符串是否符合我设定的“admin”和“123”(只是个作业,一个下午搞出来的,不想要自行车了)

程序运行文件下代码:

package com.mwt.mwtclass1;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class SignIn extends AppCompatActivity {

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

        Button button1 = (Button) findViewById(R.id.button01);
        Button button2 = (Button) findViewById(R.id.button02);

        EditText test01 = (EditText) findViewById(R.id.edit01);
        EditText test02 = (EditText) findViewById(R.id.edit02);


        Button.OnClickListener ButtonListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.button01:

                        test01.setText("");
                        test02.setText("");
                        new AlertDialog.Builder(SignIn.this)
                                .setMessage("清空成功")
                                .show();
                        return;
                    case R.id.button02:
                        if (test01.getText().toString().equals("admin") && test02.getText().toString().equals("123"))
                            new AlertDialog.Builder(SignIn.this)
                                    .setMessage("登录成功")
                                    .show();
                        else
                            new AlertDialog.Builder(SignIn.this)
                                    .setMessage("登录失败")
                                    .show();
                        return;
                }
            }
        };

        button1.setOnClickListener(ButtonListener);
        button2.setOnClickListener(ButtonListener);
    }
}

四、演示

登录成功
登录失败
清空成功

五、小结

希望下次还能在一个下午做完一个上机作业… …
这次的上机难度说实话只有两星⭐⭐,大概难就难在不知道怎么去清空内容,网上找的都是很难的函数,最后老师教了一个很简单粗暴的方式,就是把跟踪到的内容赋值为0字符串内容… …老懒鬼了,反正老师给的方法也很好用的样子,那就这样吧,学了半个月能搞出这种简单页面算不错了(懒鬼)。
图是网上找的,如果有问题请私聊,侵删。

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值