java类:
package tk.myactivity; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.widget.Button; import android.widget.TextView; public class TK_Activity01 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tk__activity01); TextView myTextView=(TextView)findViewById(R.id.myTextView); Button myButton=(Button)findViewById(R.id.myButton); myTextView.setText("我的第一个Textview"); myButton.setText("我的第一个Button" "\n" "test"); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_tk__activity01, menu); return true; } }
xml文件:
<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" > <TextView android:id="@ id/myTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" tools:context=".TK_Activity01" /> <Button android:id="@ id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RelativeLayout>