ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

第三次作业

2019-09-07 19:00:47  阅读:228  来源: 互联网

标签:Toast findViewById 第三次 EditText 作业 import android id


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:orientation="vertical"
        android:padding="30dp">
        <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="QQ"
            android:textSize="40sp" />
        <EditText
            android:id="@+id/edt1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="35dp"
            android:hint="QQ号/邮箱/手机号" />
        <EditText
            android:id="@+id/edt2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:hint="密码"
            android:password="true"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp">

            <TextView
                android:id="@+id/text2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="忘记密码?"
                android:textColor="#00aaff" />

            <TextView
                android:id="@+id/text3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:text="新用户注册"
                android:textColor="#00aaff" />
        </RelativeLayout>
        <Button
            android:id="@+id/btn1"
            android:layout_width="match_parent"
            android:layout_margin="10dp"
            android:layout_height="40dp"
            android:text="登录"
            android:textSize="20sp"
            android:background="#87CEFF"
            android:onClick="click"
            />

    </LinearLayout>



    <TextView
        android:id="@+id/text4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="30dp"
        android:text="登陆即代表阅读并同意"
        android:layout_marginLeft="56dp"
        android:textColor="#FFFAFA"
        android:textSize="20sp" />
    <TextView
        android:id="@+id/text5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/text4"
        android:layout_marginBottom="30dp"
        android:text="阅读条款"
        android:textColor="#00aaff"
        android:textSize="20sp" />



</RelativeLayout>
package com.example.wzrqq;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private Button btn1;
    EditText account = null;
    EditText code = null;
    EditText t1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t1=(EditText) findViewById(R.id.edt1);
        account = (EditText) findViewById(R.id.edt1);
        code = (EditText) findViewById(R.id.edt2);
        btn1=(Button) findViewById(R.id.btn1);
        btn1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                String username = ((EditText) findViewById(R.id.edt1)).getText().toString();
                String pwd = ((EditText) findViewById(R.id.edt2)).getText().toString();
                if (username.equals("123456") && pwd.equals("123456")) {
                    Toast.makeText(MainActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();

                } else {
                    t1.setText("账号或密码错误请重新输入");
                    Toast.makeText(MainActivity.this,"登陆失败",Toast.LENGTH_SHORT).show();
                }
            }

        });


    }
}

 

 

 

标签:Toast,findViewById,第三次,EditText,作业,import,android,id
来源: https://www.cnblogs.com/522-simple/p/11482337.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有