activity_main:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="30dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"/>
<Button
android:id="@+id/btnStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/hello_world"
/>
</LinearLayout>
import android.widget.Toast;
/**
* Created by DELL on 2016/7/13.
*/
public class HelloAndroid extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
findViewById(R.id.btnStart).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("别点我了,好吗!");
Toast.makeText(getApplicationContext(), "别点我了,好吗!", Toast.LENGTH_SHORT).show();
}
});
}
}