步步为营_Android开发课[17]_用户界面之Button(按钮)
2015-04-07 17:15
369 查看
Focus on technology, enjoy life!—— QQ:804212028
浏览链接:/article/1513032.html
主题:用户界面之Button(按钮)
Button和ImageButton控件实例:
activity_main.xml源代码:
在MainActivity.java里给它实例化并加上按钮点击的监听事件:
运行结果:
点击第一个按钮:
Logcat窗口显示
点击第二个按钮:
Logcat窗口显示
Focus on technology, enjoy life!—— QQ:804212028
浏览链接:/article/1513032.html
浏览链接:/article/1513032.html
主题:用户界面之Button(按钮)
Button和ImageButton控件实例:
activity_main.xml源代码:
<?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" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="我是Button" /> <ImageButton android:id="@+id/imgbtn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/myimage" /> </LinearLayout>
在MainActivity.java里给它实例化并加上按钮点击的监听事件:
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; public class MainActivity extends Activity { private Button btn; private ImageButton imgbtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //实例化EditText btn = (Button)findViewById(R.id.btn); imgbtn = (ImageButton)findViewById(R.id.imgbtn); btn.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Log.v("------------", "我是Button"); } }); imgbtn.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub Log.v("------------", "我是ImageButton"); } }); } }
运行结果:
点击第一个按钮:
Logcat窗口显示
点击第二个按钮:
Logcat窗口显示
Focus on technology, enjoy life!—— QQ:804212028
浏览链接:/article/1513032.html
相关文章推荐
- android用户界面之按钮(Button)教程实例汇
- Android界面UI开发中按钮Button的使用
- android开发步步为营之22:处理Activity中的back按钮事件
- 步步为营_Android开发课[20]_用户界面之Menu(菜单)
- 步步为营_Android开发课[15]_用户界面之TextView(文本视图)
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- Android用户界面开发(10):Button
- android开发步步为营之43:listview的使用(下篇:显示图片和按钮)
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- 步步为营_Android开发课[19]_用户界面之ListView(列表视图)
- android用户界面之按钮(Button)教程实例汇
- android开发中Button按钮监听事件(匿名内部类监听或者不匿名)
- Android界面UI开发中按钮Button的…
- 步步为营_Android开发课[13]_用户界面之view(视图)
- android用户界面之按钮(Button)教程实例汇
- android用户界面之按钮(Button)教程实例汇
- android 用户界面笔记之Button和ImageButton实现按钮响应事件两种方法
- Android开发之四(十三):常用控件之按钮(Button)
- 步步为营_Android开发课[16]_用户界面之EditText(编辑视图)
- 步步为营_Android开发课[14]_用户界面之Layout(布局)