Android ApiDemos示例解析(123):Views->ImageButton

ImageButton 为ImageView的子类,因此可以显示一个图形,同时它具有Button的功能,能够被按下并响应用户点击事件。ImageButton缺省显示和Button同样风格。可以在Layout文件中通过android:src 或是在代码中使用setImageResource(int) 为Button指定图像。

ImageButton可以为ImageButton重新设置背景图像。并可以为Button的不同状态(获取焦点,失去焦点,按下)指定不同的图像,比如,绿色的图像作为缺省显示,按下时显示黄色图像,获取焦点时显示橙色。一个简单的方法是使用”selector” drawable 资源,比如:

<?xml version=”1.0″ encoding=”utf-8″?>
 <selector xmlns:android=”http://schemas.android.com/apk/res/android”>
 <item android:state_pressed=”true”
 android:drawable=”@drawable/button_pressed” /> <!– pressed –>
 <item android:state_focused=”true”
 android:drawable=”@drawable/button_focused” /> <!– focused –>
 <item android:drawable=”@drawable/button_normal” /> <!– default –>
 </selector>

将中个资源文件存放在/res/drawable 目录下,然后通过android:src 为ImageButton 指定资源。 资源定义的顺序非常重要。

本例使用Android系统自带的图像资源为三个按钮指定图像:

<ImageButton
 android:layout_width=”100dip”
 android:layout_height=”50dip”
 android:src=”@android:drawable/sym_action_call” />
 
<ImageButton
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”
 android:src=”@android:drawable/sym_action_chat” />
 
<ImageButton
 android:layout_width=”wrap_content”
 android:layout_height=”wrap_content”
 android:src=”@android:drawable/sym_action_email” />



 

 

更多详细信息请查看 java教程网 http://www.itchm.com/forum-59-1.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值