package com.example.demo01;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class AnotherActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_another);
Button btn = (Button) findViewById(R.id.btn);
}
public void click(View view) {
Intent intent=new Intent();
intent.setAction("android.intent.action.VIEW");
Uri u=Uri.parse("https://im.qq.com");
intent.setData(u);
startActivity(intent);
}
}
package com.example.demo01;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.btn);
}
private TextView textView;
public void click(View view) {
Intent intent = new Intent(MainActivity.this, AnotherActivity.class);
EditText et1 = (EditText) findViewById(R.id.editText1);
EditText et2 = (EditText) findViewById(R.id.editText2);
textView = (TextView) findViewById(R.id.tv);
String s1 = et1.getText().toString();
String s2 = et2.getText().toString();
if (s1.equals("123456") && s2.equals("abc123")) {
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "登录失败", 0).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
<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.demo01.MainActivity" > <Button android:id="@+id/btn" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="32dp" android:background="#3A5FCD" android:onClick="click" android:text="QQ" android:textSize="20sp" android:textColor="#FFFFFF" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="174dp" android:textSize="40sp" android:text="登录成功" /> </RelativeLayout>
<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.demo01.MainActivity" > <ImageView android:id="@+id/picture" android:layout_width="80dp" android:layout_height="80dp" android:layout_centerHorizontal="true" android:layout_marginTop="58dp" android:src="@drawable/picture" /> <EditText android:id="@+id/editText2" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editText1" android:layout_below="@+id/editText1" android:layout_marginTop="19dp" android:ems="10" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText2" android:layout_alignBottom="@+id/editText2" android:layout_alignLeft="@+id/textView1" android:text="密码:" android:textSize="20sp" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/btn" android:layout_centerHorizontal="true" android:layout_marginTop="29dp" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/editText2" android:layout_alignParentLeft="true" android:layout_marginLeft="30dp" android:text="账号:" android:textSize="20sp" /> <Button android:id="@+id/btn" android:layout_width="250dp" android:layout_height="wrap_content" android:layout_below="@+id/editText2" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:background="#3A5FCD" android:onClick="click" android:text="登录" android:textColor="#FFFFFF" /> <EditText android:id="@+id/editText1" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_below="@+id/picture" android:layout_marginTop="24dp" android:layout_toRightOf="@+id/textView1" android:ems="10" android:textColor="#000000" android:textSize="20sp" /> </RelativeLayout>