<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" //1.5以后默认的是LinearLayout布局 android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textview1" //定义Id方便Java类找到它,并且控制它 android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/button1" android:layout_width="60px" android:layout_height="wrap_content" android:layout_gravity="right" //让Button放在右面 android:text="确定" /> </LinearLayout>
package com.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class ButtonDemo extends Activity {
private TextView textview1;
private Button button1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//通过ID在找到定义在main.xml里的TextView和Button控件
textview1 = (TextView)findViewById(R.id.textview1);
button1 = (Button)findViewById(R.id.button1);
//增加事件响应
button1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v)
{
//Toast提示控件
Toast.makeText(ButtonDemo.this,
"TextView里的文字发生了改变,你注意到了吗?",
Toast.LENGTH_LONG).show();
//将TextView的文字发生改变
textview1.setText("欢迎来到魏祝林的博客!");
}
});
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有