加入收藏 | 设为首页 | 会员中心 | 我要投稿 我爱故事小小网_铜陵站长网 (http://www.0562zz.com/)- 视频终端、云渲染、应用安全、数据安全、安全管理!
当前位置: 首页 > 教程 > 正文

Android下按钮的使用技巧

发布时间:2021-12-18 15:21:02 所属栏目:教程 来源:互联网
导读:Android下按钮的使用方法: 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
Android下按钮的使用方法:
 
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(){  //成员按钮监听对象   
    @Override  
    public void onClick(View v) {                                             //按钮事件   
        // TODO Auto-generated method stub   
        setTitle("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>  

(编辑:我爱故事小小网_铜陵站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读