07
package com.example.qq; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends ActionBarActivity implements OnClickListener { TextView textView; EditText username; EditText password; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); username = (EditText) findViewById(R.id.username); password = (EditText) findViewById(R.id.password); textView = (TextView) findViewById(R.id.textView1); Button btn = (Button) findViewById(R.id.button1); btn.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub String username1 = username.getText().toString(); String password1 = password.getText().toString(); // TODO Auto-generated method stub if (username1.equals("123456") && password1.equals("123456")) { Intent intent = new Intent(); intent.setClass(MainActivity.this, secendActivity.class); Bundle bundle = new Bundle(); bundle.putString("username1", "123456"); bundle.putString("password1", "123456"); intent.putExtras(bundle); startActivity(intent); finish(); } if (!username1.equals("123456") && !password1.equals("123456")) { String s="登录失败"; textView.setText(s); } } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" 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.qq.MainActivity" > <TextView android:id="@+id/tv_account" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:background="#FFFFFF" android:text="帐号:" android:textSize="30dp" /> <TextView android:id="@+id/tv_account1" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_below="@+id/tv_account" android:layout_centerVertical="true" android:background="#FFFFFF" android:text="密码:" android:textSize="30dp" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tv_account1" android:layout_alignRight="@+id/tv_account1" android:layout_below="@+id/tv_account1" android:background="#545bcb" android:textColor="#ffffff" android:textSize="20dp" android:text="登录" android:onClick="CCC"/> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_above="@+id/tv_account" android:src="@drawable/logo" /> <EditText android:id="@+id/password" android:layout_width="400dp" android:layout_height="40dp" android:layout_below="@+id/tv_account" android:ems="10" android:gravity="center" android:background="@null" /> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="40dp" android:layout_centerInParent="true" android:ems="10" android:gravity="center" android:background="@null" /> <TextView android:id="@+id/textView1" android:layout_width="400dp" android:layout_height="40dp" android:layout_centerHorizontal="true" android:layout_below="@+id/button1" /> </RelativeLayout>
package com.example.qq; import android.support.v7.app.ActionBarActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class secendActivity extends ActionBarActivity { TextView tv2; TextView tv4; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.secend); Intent intent = getIntent(); Bundle bundle=intent.getExtras();//.getExtras()得到intent所附带的额外数据 String uname=bundle.getString("username1"); String upwd=bundle.getString("password1"); tv2=(TextView) findViewById(R.id.textView2); tv4=(TextView) findViewById(R.id.textView4); tv2.setText(uname); tv4.setText(upwd); } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" 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.qq.secendActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="你的账号是:" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView1" android:layout_alignBottom="@+id/textView1" android:layout_marginLeft="28dp" android:layout_toRightOf="@+id/textView1" android:text="" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="17dp" android:text="你的密码是:" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView3" android:layout_alignBottom="@+id/textView3" android:layout_marginLeft="14dp" android:layout_toRightOf="@+id/textView3" android:text="" /> </RelativeLayout>