第三次安卓作业

mac2022-06-30  240

<?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="#FFF0F5"> <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:drawableLeft="#333fff" 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_height="wrap_content" android:text="登录" android:textSize="20sp" android:onClick="click"/> </LinearLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/text4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="50dp" android:text="登陆即代表阅读并同意阅读条款" android:textColor="#00aaff" android:textSize="20sp" /> </RelativeLayout> </RelativeLayout> package com.example.qqqq; 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; TextView information = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); account = (EditText) findViewById(R.id.edt1); information = (TextView) findViewById(R.id.text1); 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 { Toast.makeText(MainActivity.this,"密码错误",Toast.LENGTH_SHORT).show(); } } }); } }

转载于:https://www.cnblogs.com/QXY-1/p/11491143.html

相关资源:JAVA上百实例源码以及开源项目

最新回复(0)