Android 应用开发笔记 - 按钮(Button, ImageButton)
2012-09-14 22:22
459 查看
我们在讲Toast时,已经使用了Button。首先,在面板拖拽图标
,然后更改相关属性(Properties),如下图:
activity_main.xml清单如下:
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="52dp"
android:layout_marginTop="76dp"
android:text="@string/btn1Caption"
android:textSize="@dimen/font_size20"
/>
然后,我们开始编码。
其相关部分的代码如下:
Button btnOk = (Button) findViewById(R.id.btnOk);
btnOk.setOnClickListener(this);
效果如下图:
,然后更改相关属性(Properties),如下图:
activity_main.xml清单如下:
<ImageButton
android:id="@+id/imgBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkBox2"
android:layout_alignTop="@+id/spin01"
android:contentDescription="@string/btn1Caption"
android:onClick="@string/hello_world"
android:src="@drawable/ic_launcher"
/>
然后,我们开始编码。
其相关部分的代码如下:
// ImageButton
ImageButton imgBtn1 = (ImageButton)findViewById(R.id.imgBtn1);
imgBtn1.setOnClickListener(newButton.OnClickListener() {
@Override
public
void onClick(View arg0) {
// TODO Auto-generatedmethod stub
setToastString("Hello China").show();
}
});
效果如下图:
,然后更改相关属性(Properties),如下图:
activity_main.xml清单如下:
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="52dp"
android:layout_marginTop="76dp"
android:text="@string/btn1Caption"
android:textSize="@dimen/font_size20"
/>
然后,我们开始编码。
其相关部分的代码如下:
Button btnOk = (Button) findViewById(R.id.btnOk);
btnOk.setOnClickListener(this);
效果如下图:
4.2.6 带图标的按钮(ImageButton)
在面板拖拽图标,然后更改相关属性(Properties),如下图:
activity_main.xml清单如下:
<ImageButton
android:id="@+id/imgBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/chkBox2"
android:layout_alignTop="@+id/spin01"
android:contentDescription="@string/btn1Caption"
android:onClick="@string/hello_world"
android:src="@drawable/ic_launcher"
/>
然后,我们开始编码。
其相关部分的代码如下:
// ImageButton
ImageButton imgBtn1 = (ImageButton)findViewById(R.id.imgBtn1);
imgBtn1.setOnClickListener(newButton.OnClickListener() {
@Override
public
void onClick(View arg0) {
// TODO Auto-generatedmethod stub
setToastString("Hello China").show();
}
});
效果如下图:
相关文章推荐
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- Android开发总结笔记 Button和ImageButton(按钮) 1-1-9
- android 用户界面笔记之Button和ImageButton实现按钮响应事件两种方法
- android应用开发揭秘examples_04-12笔记(Button的使用)
- android应用开发揭秘examples_04-16笔记(ImageButton的使用)
- Android开发学习笔记--给一个按钮定义事件
- Android 应用开发笔记 - 单项选择(RadioGroup, RadioButton)
- Android应用开发学习笔记之AsyncTask
- Android应用开发笔记(12):Android应用的自动升级、更新模块的实现
- 【读书笔记-《Android游戏编程之从零开始》】3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
- Android应用开发笔记
- android 防止按钮连续点击的方法(Button,ImageButton等)
- 【Android 应用开发】Android 网络编程 API笔记 - java.net 包 权限 地址 套接字 相关类 简介
- 多选按钮(作业)--MarsChen Android 开发教程笔记
- Android应用开发学习笔记之Intent
- Android高级应用开发(基础篇) - stage6 - 学习笔记(下)
- Android应用开发笔记(11):Android上的蓝牙通信功能的开发:BluetoothChat例程分析
- Android进阶笔记07:用MVP架构开发Android应用(MVC 和 MVP)