MainActivity.java

package com.example.empty_project;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
      //实现背景图全面屏
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
      //获得控件的引用
Button button = (Button)findViewById(R.id.button);
EditText username = (EditText)findViewById(R.id.username) ;
EditText password = (EditText)findViewById(R.id.password) ;
      //button添加监听,OnClickListener是View类下的内部接口
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
          //通过getText()获得EditText的值,使用equals比较,因为equals是内容比较而==是地址比较
if(username.getText().toString().equals("admin") && password.getText().toString().equals("123456")){
          //Toast.makeText()弹框提示, 第一个参数为本类,第二个参数是内容,第三个参数是摊开停留时间
Toast.makeText(MainActivity.this,"您已成功登录",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this,"登录失败",Toast.LENGTH_LONG).show();
}
}
}); }
}
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/background"
android:orientation="vertical"
tools:context=".MainActivity"
tools:layout_editor_absoluteX="-115dp"
tools:layout_editor_absoluteY="-16dp"> <TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFE4C4"
android:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="账 号:" /> <EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="输入账号"
android:maxLength="11" /> </LinearLayout> <!--密码-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <TextView
android:layout_width="70dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="密 码:" /> <EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:inputType="textPassword" />
</LinearLayout> <Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="登录"
android:textSize="20sp"
/> </LinearLayout> <TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" /> </LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout>

android --一个简单的登录界面的更多相关文章

  1. CSS样式案例(2)-制作一个简单的登录界面

    首先来张完工的效果图. 一.html文件如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  2. IOS制作一个漂亮的登录界面

    上图是Facebook的登录界面,看起来很漂亮,eamil框和passwod框合在一起,那么这种效果是怎么做出来的呢?我们都知道输入框用layer属性是可以做成圆角的形式,那么怎么样才能够仅仅只让上边 ...

  3. sencha做个简单的登录界面

    很多人都在群里问要一个好看的登录界面,我表示很无奈,哪有好看的,每个人的要求不一样,要好看的只有自己做. 下面是我自己整理的一个通用版的登录界面,稍做修改,很容易能变成你想要的界面, 不说废话,直接上 ...

  4. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  5. 7. Swift 基于Xmpp和openfire实现一个简单的登录注册

    1. 基本步骤:首先导入Xmpp框架,配置环境 ->由于我们使用的是OC的Xmpp框架,再进行Swift开发时需要进行桥接. 具体方法就是创建一个基于c的.h的头文件,然后将我们需要编译OC的语 ...

  6. jmeter 压力测试(一)一个简单的登录

    写在最前面,之所以记录这个最最简单的http的登录,是因为捣鼓了一天,真的是找错也找不错了,后来请教的同事,重新写了一个ok了,最后发现竟然是因为[http信息头]写的有问题,简直是!!醉了 如下,这 ...

  7. Appium+python 一个简单的登录测试实例

    # coding=utf-8 from appium import webdriver import time import unittest import os import HTMLTestRun ...

  8. JAVA web简单的登录界面jsp实现

    此次试验所用到的软件是myeclipse10,tomcat7,Dreamweaver,sqlserver2008数据库.可以实现用户使用用户名和密码登录.如果登录成功,页面会显示登录成功,如果密码错误 ...

  9. 第四章 .net core做一个简单的登录

    项目目标部署环境:CentOS 7+ 项目技术点:.netcore2.0 + Autofac +webAPI + NHibernate5.1 + mysql5.6 + nginx 开源地址:https ...

随机推荐

  1. Java动态绑定和静态绑定-多态

    一.问题 Java方法调用过程中,Jvm是如何知道调用的是哪个类的方法?Jvm又是如何处理?   二.概念 a.当子类和父类(接口和实现类)存在同一个方法时,子类重写父类(接口)方法时,程序在运行时调 ...

  2. SpringMVC之RedirectAttributes属性

    RedirectAttributes是SpringMVC3.1版本之后出来的一个新功能,专门用于重定向之后还能带参数跳转的的工具类. 两种带参方式: redirectAttributes.addAtt ...

  3. 【以太坊剖析】以太坊虚拟机(EVM)之基本定义

    以太坊虚拟机(EVM) 以太坊虚拟机(Ethereum Virtual Machine,简称EVM)是一个基于栈的虚拟机,基于特定的环境数据,执行一系列的字节代码形式的指令,以修改系统状态.EVM目前 ...

  4. libcurl库openssl编译

    openssl编译 win32: perl Configure  no-shared VC-WIN32 --prefix=E:/lib/openssl-1.1.1 linux: ./config -f ...

  5. bom案例3-放大镜

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. Plist存储

  7. Java程序性能监控工具

    系统性能监控: 确定系统运行的整体状态,基本定位问题所在 uptime命令 [root@localhost ~]# uptime23:19:38 up 244 days, 3:39, 34 users ...

  8. mysql查询奇数行或者偶数行数据

    select * from (select @rownum := @rownum+1 as row_num, t.* from 表名 t,(select @rownum:=0) tmp_table o ...

  9. Linux忘记Root密码怎么找回

    进入1级别,单用户模式 ,修改root密码即可(运行级别不懂看这里) 具体操作如下: 1.开机时按enter键 2.进入GRUB界面 3.输入 e,在引导系统前编辑命令 4.选择第二行 kernel ...

  10. 【论文总结】Zero-Shot Semantic Segmentation

    论文地址:https://arxiv.org/abs/1906.00817 代码:https://github.com/valeoai/ZS3 一.内容 Step 0:首先使用数据集(完全不包含 Un ...