package com.hangsheng.button;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;public class Ex07_WidgetButtonActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);   //关联布局模板文件main.xml        find_and_modify_button();        //调用成员函数find_and_modity_button    }   private void find_and_modify_button(){   Button button =(Button)findViewById(R.id.button);        //通过资源内ID为button的资源来实例化button对象   button.setOnClickListener(button_listener);              //设置对象button的监听器      };   private Button.OnClickListener button_listener =new Button.OnClickListener(){  //成员按钮监听对象@Overridepublic void onClick(View v) {                       //按钮事件// TODO Auto-generated method stubsetTitle("button被点击了一下");}   };}
布局模板文件main.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/hello" />    <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="这是Button" /></LinearLayout>

更多相关文章

  1. android 开发 简单的页面布局
  2. android 弹出带按钮的对话框
  3. RecyclerView竖直和水平的瀑布流布局
  4. 在android中创建包含对象数组对象List 的Parcelable
  5. Android适配底部虚拟键盘遮挡布局的解决方案
  6. Android参数设置父布局集体宽高

随机推荐

  1. 越过Android中布局文件中使用onClick属性
  2. Android仿美团分类下拉菜单实例代码
  3. Android 数据库事务的个人理解
  4. Android使用faq
  5. Android studio64新建APP项目时,报错 jun
  6. Android(安卓)Inflate 的使用
  7. [置顶] Android第三方库学习清单
  8. Android studio查看SQLIte数据库文件
  9. 笔记之Android(安卓)Bluetooth OOP 传送
  10. Android 实现弧形字体渐变文字