Android安卓登录页面

效果展示

虽然说以前学了点,但是还是是个菜鸡。现在又来学一哈,hhh。Java大法好

先看看效果图吧

效果展示

项目地址

百度云:链接:https://pan.baidu.com/s/1Zq7Voo-KW6_AkZIqdgap4g 提取码:u0ze

蓝凑云:https://yxqz.lanzoui.com/ilpyWgqpene

布局介绍

  1. 帧布局 framelayout
  2. 线性布局 LinearLayout
  3. 表格布局 TableLayout
  4. 相对布局 RelativeLayout

帧布局

可以理解为相框,里面的视图就是照片

  • 默认在左上角
  • 后方的视图会往上叠加,从而覆盖之前的视图

线性布局

  • 像一个需要按顺序排放的展柜
  • 可以规定线性布局是按竖直和横向排列

表格布局

  • 由行和列构成
  • 将视图放在行和列组成的单元格里

相对布局

  • 一种很灵活的布局方式
  • 放入的视图位置可以根据已有视图的相对位置确定
  • 默认的Android布局

图片位置

在app下的res下的drawable下面

图片位置

登录页面

登录界面(activity_main.xml)

使用了表格布局,还有线性布局,纯手打。hhh。拖动我英语不行,懒得汉化了。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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/shoujibizhi"
    tools:context=".MainActivity">

    <!--欢迎处的表格布局   -->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="center">

        <!--    欢迎字体-->

        <TextView
            android:gravity="center"
            android:text="欢迎登录"
            android:textColor="#B97E05"
            android:textSize="40dp"></TextView>
    </TableLayout>


    <!--    文本框的Ta布局-->
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:gravity="center">

        <!--        用户名-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="用户名:"
                android:textColor="#B97E05" />

            <EditText
                android:id="@+id/usernameET"
                android:layout_width="200dp"
                android:layout_height="wrap_content" />

        </LinearLayout>

        <!--        密码-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密     码:"
                android:textColor="#B97E05" />

            <EditText
                android:id="@+id/passET"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:password="true" />

        </LinearLayout>
<!--        账号和密码提示-->
        <LinearLayout
            android:gravity="center">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20dp"
                android:textColor="#BA0109"
                android:text="用户名是admin,密码是123"
                />
        </LinearLayout>
    </TableLayout>


    <!--    按钮的Tab布局-->
    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:gravity="center">
<!--        使用线性布局-->

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center">
            <Button
                android:id="@+id/loginButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background=" #F3DB26"
                android:text="登 录"
                android:textSize="18dp" />
            <Button
                android:id="@+id/zcButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="100dp"
                android:background=" #F3B2"
                android:text="注册"
                android:textSize="18dp" />
        </LinearLayout>
    </TableLayout>

</TableLayout>

属性解析

  1. android:layout_width=“match_parent”:界面宽度,match_parent表示充满屏幕 这里是让宽度充满屏幕可以用行来理解
  2. android:layout_height=“match_parent” 界面高度。wrap_content表示根据内容来调节,这里是调节高度
  3. layout_marginLeft:界面左边外边距.
  4. gravity=“center”:内容居中
  5. android:layout_gravity=“center”:界面居中
  6. android:password=“true”:密码属性

逻辑代码(MainActivity.java)

package com.yq.text;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button lgButton, zcButton;
    private EditText usernameText, passText;
    
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
//        设置页面布局 ,main界面
        setContentView( R.layout.activity_main );
        //设置此界面为竖屏
        setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT );
//       初始化方法
        init();
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    private void init() {
        //从main.xml 页面布局中获取对应的UI控件
        lgButton = (Button) findViewById( R.id.loginButton );
        zcButton = (Button) findViewById( R.id.zcButton );
        usernameText = (EditText) findViewById( R.id.usernameET );
        passText = (EditText) findViewById( R.id.passET );
// 注册按钮监听
        zcButton.setOnClickListener( new OnClickListener() {
            //注册按钮实现事件
            public void onClick(View v) {
                Toast.makeText( MainActivity.this, "老师没说做这个", Toast.LENGTH_SHORT ).show();
            }
        } );

        //登录按钮的点击事件
        lgButton.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick(View v) {
                //非空
                if ("".equals( usernameText.getText().toString() ) == true ||
                        "".equals( passText.getText().toString() ) == true
                ) {
                    Toast.makeText( MainActivity.this, "没有输入账号或者密码~~~", Toast.LENGTH_SHORT ).show();
				// 逻辑判断
                } else if ("admin".equals( usernameText.getText().toString() ) == true &&
                        "123".equals( passText.getText().toString() ) == true
                ) {
                    //提示用户名
                    Toast.makeText(MainActivity.this, "欢迎你:"+usernameText.getText().toString(), Toast.LENGTH_SHORT).show();
                    //创建登录成功界面对象
                    Intent intent = new Intent( MainActivity.this, LoginSourcess.class );
                    startActivity( intent );//打开界面
                    MainActivity.this.finish();//终结登录界面
                }else{
                    //输入要错误提示
                    Toast.makeText(MainActivity.this, "请不要乱输入", Toast.LENGTH_SHORT).show();
                }


            }
        } );


    }
}

登录成功的页面

成功页面(loginsoucess.xml)

<TableLayout 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/shouj"
    tools:context=".MainActivity">

    <TextView
        android:textSize="100dp"
        android:text="登录成功"
        />
</TableLayout>

逻辑代码(LoginSourcess.java)

package com.yq.text;

import android.content.pm.ActivityInfo;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

public class LoginSourcess extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        设置页面布局
        setContentView(R.layout.loginsoucess);
        //设置此界面为竖屏
        setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

页面配置

这里是很多人忘记配置的地方,也是做跳转的时候,会报一个页面无法打开的异常

找到app下的manifests文件夹里的AndroidManifest.xml文件

在application标签下添加新建的登录成功页面.这里是通过调用java文件来对页面进行操作。

        <activity android:name=".LoginSourcess"/>

activity配置

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个简单的Android登录页面的示例代码: 1. 首先,在布局文件中创建一个EditText用于输入用户名,一个EditText用于输入密码,一个Button用于提交登录信息。 ```xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/et_username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名" /> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:hint="请输入密码" /> <Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" /> </LinearLayout> ``` 2. 在LoginActivity.java中,找到布局文件中的控件,并为登录按钮设置点击事件。 ```java public class LoginActivity extends AppCompatActivity { private EditText etUsername; private EditText etPassword; private Button btnLogin; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); etUsername = findViewById(R.id.et_username); etPassword = findViewById(R.id.et_password); btnLogin = findViewById(R.id.btn_login); btnLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String username = etUsername.getText().toString(); String password = etPassword.getText().toString(); // 在这里处理登录逻辑 } }); } } ``` 3. 在AndroidManifest.xml文件中注册LoginActivity。 ```xml <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我最爱吃鱼香茄子

请小余喝瓶杯咖啡吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值