项目一——登录窗口

1,项目效果展示及源代码

1):效果展示:开始页面

 登录进去的页面

源码展示

俩个Java文件代码

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    EditText name;
    EditText passwd;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ping_layout);
        name=findViewById(R.id.name);
        passwd=findViewById(R.id.passwd);


    }
    public void Login(View v){
        String Usename="admin";
        String Upwd="12345";
        String user=name.getText().toString().trim();
        String pwd=passwd.getText().toString().trim();
        if(user.equals(Usename)&pwd.equals(Upwd)){
            Toast.makeText(this,"欢迎进入,小可爱们,再次点击进入",Toast.LENGTH_SHORT).show();
            Button button=findViewById(R.id.button);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent();
                    intent.setClass(MainActivity.this,TestActivity2.class);
                    startActivity(intent);
                }
            });
        }else{
            Toast.makeText(this,"真是抱歉呢,我好像不认识你",Toast.LENGTH_SHORT).show();
        }
    }



}

俩个布局代码

开始页面布局

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:background="@drawable/tree"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="静静子的登录窗口"
        android:textColor="#EFECE7"
        android:textSize="15sp"/>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginLeft="200dp"
        android:layout_marginTop="75dp"
        android:layout_marginRight="30dp"
        android:src="@drawable/yky"
        />


    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="100dp"
        android:inputType="text"
        android:hint="请输入用户名"
        android:gravity="center_horizontal"
        android:textColorHint="#FBFAFA"
        android:ems="12"
        />
    <ImageView
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="-40dp"
        android:layout_marginRight="30dp"
        android:src="@drawable/yong"
        />
    <EditText
        android:id="@+id/passwd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="40dp"
        android:inputType="textPassword"
        android:hint="请输入密码"
        android:gravity="center_horizontal"
        android:textColorHint="#cccccc"
        android:ems="12"/>
    <ImageView
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="-40dp"
        android:layout_marginRight="30dp"
        android:src="@drawable/mima" />
    <CheckBox
        android:id="@+id/remember_pass"
        android:layout_marginLeft="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
         <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="显示密码"
             android:layout_marginTop="-35dp"
             android:layout_marginLeft="60dp"/>
    <CheckBox
        android:id="@+id/remember_pass2"
        android:layout_marginLeft="260dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="-30dp"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="忘记密码?"
        android:layout_marginTop="-35dp"
        android:layout_marginLeft="300dp"/>



    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录"
        android:layout_marginLeft="200dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="40dp"
        android:onClick="Login"/>


</LinearLayout>

进入页面布局

<?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:layout_width="500dp"
    android:layout_height="match_parent"
    tools:context=".TestActivity2"
    android:orientation="vertical"
    android:background="@drawable/ddd">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="  你是我心中的一句惊叹,惊叹世界万物原来可以如此温柔"
        android:textColor="#009688"
        android:textSize="40sp"
        ></TextView>

</LinearLayout>

2,在操作中遇见的错误:

注意有些符号不能出现在代码中

1,在第一个界面布局完成时,无法运行,系统提示textView中不能出现">"这个符号,此时需要注意,在自己写的项目下是没有出现这种错误的,但是与项目在同一个文件夹下的其他项目有,所以要记得检查同一个文件夹下的代码是否错误。

在放图片的代码中,如果没有放上图片路径,也是会报错的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值