<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.homework7.MainActivity" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:src="@drawable/qq" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="130dp" android:orientation="horizontal" > <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号:" android:textSize="25sp" /> <EditText android:id="@+id/et1" android:layout_width="match_parent" android:layout_height="40dp"/> </LinearLayout> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="190dp" android:orientation="horizontal" > <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" android:textSize="25sp" /> <EditText android:id="@+id/et2" android:layout_width="match_parent" android:layout_height="40dp"/> </LinearLayout> <Button android:id="@+id/button" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="56dp" android:onClick="onclick" android:text="登录" /> </RelativeLayout> <?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" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="105dp" android:orientation="horizontal" > <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示账号:" android:textSize="20sp" /> <TextView android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="40dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/linearLayout1" android:layout_marginTop="14dp" android:orientation="horizontal" > <TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示密码:" android:textSize="20sp" /> <TextView android:id="@+id/tv4" android:layout_width="match_parent" android:layout_height="40dp" /> </LinearLayout> </RelativeLayout> <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.homework7" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity2"></activity> <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
package com.example.zuoyeqi; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends ActionBarActivity { private EditText et1; private EditText et2; private Button bt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bt=(Button)findViewById(R.id.button); et1=(EditText)findViewById(R.id.et1); et2=(EditText)findViewById(R.id.et2); } public void onclick(View v) { String ID="123456"; String PassWord="abc123"; String s1=et1.getText().toString(); String s2=et2.getText().toString(); if (ID.equals(s1)&&PassWord.equals(s2)) { Toast.makeText(MainActivity.this, "登录成功", 1).show(); Intent intent=new Intent(MainActivity.this,MainActivity2.class); intent.putExtra("zh",s1); intent.putExtra("mm",s2); startActivity(intent); } else { Toast.makeText(MainActivity.this, "登录失败", 1).show(); } } } package com.example.zuoyeqi; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class MainActivity2 extends ActionBarActivity { private TextView tv1; private TextView tv2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_main); tv1 = (TextView) findViewById(R.id.tv2); tv2=(TextView) findViewById(R.id.tv4); Intent intent=getIntent(); String ID=intent.getStringExtra("zh"); String PassWord=intent.getStringExtra("mm"); tv1.setText(ID); tv2.setText(PassWord); } }