Actyivity:
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
//添加Button按钮 设置其ID;宽高;等等
<Button
android:id="@+id/b1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/t1"
android:layout_below="@+id/t1"
android:layout_marginTop="41dp"
android:onClick="dj"
android:text="点我增长1cm" />
JAVA:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_main);
//获取TextView,Button控件
final TextView tv=(TextView) findViewById(R.id.t1);
tv.setText("现在时间---请看你的手机!!");
final Button btn = (Button)findViewById(R.id.b1);
//设置点击后TextView现实的内容
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv.setText("想得美");
}
});
运行效果: