1. //1.activity_main
    2. <Button
    3. android:id="@+id/main_btn"
    4. android:layout_width="wrap_content"
    5. android:layout_height="wrap_content"
    6. android:text="按钮" />
    1. //2.MainActivity
    2. Button btn=(Button) findViewById(R.id.main_btn);
    3. btn.setOnClickListener(new View.OnClickListener() {
    4. @Override
    5. public void onClick(View v) {
    6. Toast.makeText(MainActivity.this,"android牛逼",Toast.LENGTH_SHORT).show();
    7. }
    8. });