android控件05 Button

来源:互联网 发布:苹果电脑不能淘宝付款 编辑:程序博客网 时间:2024/06/05 05:21

1)/res/layout/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" >   <Button android:id="@+id/button"       android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="按钮"       /></LinearLayout>

2)com.sxt.ButtonActivity

package com.sxt;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class ButtonActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        Button button =(Button)this.findViewById(R.id.button);         button.setOnClickListener(new OnClickListener() {public void onClick(View v) {// TODO Auto-generated method stubToast.makeText(ButtonActivity.this,  "You click the button", Toast.LENGTH_SHORT).show();}});    }}

3)如图



原创粉丝点击