<?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="@drawable/dengluye"> <ImageView android:id="@+id/touxiang" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/touxiang02" android:layout_marginTop="100dp" android:layout_centerHorizontal="true"> </ImageView> <EditText android:id="@+id/et01" android:layout_width="match_parent" android:layout_height="50dp" android:layout_below="@id/touxiang" android:background="#9D9D9D" android:layout_marginTop="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:hint="账号/手机号"> </EditText> <EditText android:id="@+id/et02" android:layout_width="match_parent" android:layout_height="50dp" android:layout_below="@id/et01" android:layout_marginTop="2dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="#ADADAD" android:inputType="textPassword"> </EditText> <Button android:id="@+id/btn02" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/button_shape" android:text="登录" android:layout_below="@id/et02" /> <Button android:id="@+id/btnzc2" android:layout_width="200dp" android:layout_height="wrap_content" android:onClick="click" android:layout_marginTop="400dp" android:layout_centerHorizontal="true" android:background="@drawable/button_shape" android:text="未有账号?请注册" /> </RelativeLayout>
package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener { private ListView mListView; private EditText dengluzh; private EditText denglumm; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN ); setContentView(R.layout.denglu); dengluzh = (EditText) findViewById(R.id.et01); denglumm = (EditText) findViewById(R.id.et02); Button login = (Button) findViewById(R.id.btn02); Button zc2 = (Button) findViewById(R.id.btnzc2); login.setOnClickListener(this); zc2.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn02: String zh = dengluzh.getText().toString(); String mm = denglumm.getText().toString(); if ("13164557510".equals(zh)&&"sqlzhs521".equals(mm)){ Intent intent = new Intent(MainActivity.this,MyActivity.class); startActivity(intent); }else { Toast.makeText(MainActivity.this,"登陆失败",Toast.LENGTH_SHORT).show(); } break; case R.id.btnzc2: Intent intent = new Intent(); intent.setClass(MainActivity.this,zhuceActivity.class); startActivity(intent); break; } } }
来源:https://www.cnblogs.com/LXF-i/p/12006131.html