简单用户登录界面

一、要求:设计如下图所示的界面
在这里插入图片描述
二、涉及知识点
(1)利用到布局的嵌套实现复杂界面
(2)居中对齐,利用线性布局的gravity属性
(3)标签、编辑框、按钮三种控件
(4)编辑框的提示信息,利用hint属性
三、实现步骤:
1、创建安卓应用Login
在这里插入图片描述
2、准备背景图片,拷贝到res下的mipmap目录里
在这里插入图片描述
3、字符串资源文件strings.xml
在这里插入图片描述

<resources>
    <string name="app_name">用户登录</string>
    <string name="user_login">用户登录</string>
    <string name="user">用户:</string>
    <string name="user_hint">请输入用户名</string>
    <string name="password">密码:</string>
    <string name="password_hint">请输入密码</string>
    <string name="login">登录</string>
    <string name="cancel">取消</string> </resources>

4、布局文件activity_login.xml
在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@mipmap/background">

    <TextView
        android:id="@+id/tv_user_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="@string/user_login"
        android:textSize="30dp"
        android:textColor="#2ea1a8"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/tv_username"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/username"
            android:textSize="20dp"/>
        <EditText
            android:id="@+id/edt_user"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/user_hint"
            android:singleLine="true"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/tv_password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/password"
            android:textSize="20dp"/>
        <EditText
            android:id="@+id/edt_password"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:hint="@string/password_hint"
            android:ems="10"
            android:inputType="textPassword"
            android:singleLine="true"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:id="@+id/btn_login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/login" />
        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/cancel"/>
    </LinearLayout>

</LinearLayout>

5、登录界面类LoginActivity
在这里插入图片描述

public class LoginActivity extends Activity {

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

6、在项目清单文件里设置启动Activity
在这里插入图片描述

如上,登录界面就做好了。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值