就不细说项目的设置什么的了,直接从添加Activity开始。
如图,src文件夹下添加一个ButtonActivity
View Code package cn.Kurodo; import cn.Kurodo.R.id; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.Button; import android.view.View; import android.view.View.OnClickListener; public class ButtonActivity extends Activity { public ButtonActivity() { // TODO Auto-generated constructor stub } @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.button); // 找到Btn_Test的按钮控件 Button testBtn = (Button)findViewById(id.Btn_Test); // 单击事件的监听 testBtn.setOnClickListener( new OnClickListener(){ @Override public void onClick(View v) { // LogCat下的输出 Button btn = (Button)v; Log.v( " Button " ,String.valueOf(btn.getText())); } }); }}
然后再lay文件夹添加一个button.xml的布局
View Code <? xml version="1.0" encoding="utf-8" ?> < LinearLayout xmlns:android ="http://schemas.android.com/apk/res/android" android:orientation ="vertical" android:layout_width ="fill_parent" android:layout_height ="fill_parent" > < Button android:id ="@+id/Btn_Test" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:text ="@string/btn_test" /> </ LinearLayout >
最后修改项目的Manifest文件。修改最先启动的Activity为我们添加的ButtonActivity
View Code <? xml version="1.0" encoding="utf-8" ?> < manifest xmlns:android ="http://schemas.android.com/apk/res/android" package ="cn.Kurodo" android:versionCode ="1" android:versionName ="1.0" > < uses-sdk android:minSdkVersion ="4" /> < application android:icon ="@drawable/icon" android:label ="@string/app_name" > < activity android:name =".ButtonActivity" android:label ="@string/app_name" > < intent-filter > < action android:name ="android.intent.action.MAIN" /> < category android:name ="android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > </ application > </ manifest >
运行效果
转载于:https://www.cnblogs.com/Kurodo/archive/2011/07/31/2122745.html
相关资源:Android 自定义控件 EditText输入框两边加减按钮Button Demo