package com.baishiji.www;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Button b1,b2,b3,b4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1= (Button) findViewById(R.id.btn_contacts);
b2= (Button) findViewById(R.id.btn_discover);
b3= (Button) findViewById(R.id.btn_wechat);
b4= (Button) findViewById(R.id.btn_me);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btn_contacts :
Toast.makeText(MainActivity.this, "btn_contacts", Toast.LENGTH_SHORT).show();
break;
case R.id.btn_discover :
Toast.makeText(MainActivity.this, "btn_discover", Toast.LENGTH_SHORT).show();
break;
case R.id.btn_wechat :
Toast.makeText(MainActivity.this, "btn_wechat", Toast.LENGTH_SHORT).show();
break;
case R.id.btn_me :
Toast.makeText(MainActivity.this, "btn_me", Toast.LENGTH_SHORT).show();
break;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<LinearLayout
android:id="@+id/ll_container"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_wechat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="wechat"
android:text="微信" />
<Button
android:id="@+id/btn_contacts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="contacts"
android:text="通讯录" />
<Button
android:id="@+id/btn_discover"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="discover"
android:text="发现" />
<Button
android:id="@+id/btn_me"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="me"
android:text="我" />
</LinearLayout>
</LinearLayout>