Chinaunix首页 | 论坛 | 博客
  • 博客访问: 166769
  • 博文数量: 24
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 399
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-04 15:36
文章分类

全部博文(24)

文章存档

2017年(2)

2015年(5)

2014年(9)

2013年(8)

我的朋友

分类: Android平台

2015-02-07 22:17:29

一般地如果使用一个ImageButton时,一般都会定义一个drawable.xml用来描述Button弹起/按下时的图标变化,例如:

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="" >
  3.     <item
  4.         android:state_pressed="true"
  5.         android:drawable="@drawable/gear_wheel_icon" />
  6.     <item
  7.         android:state_pressed="false"
  8.         android:drawable="@drawable/phone_icon" />
  9.         
  10. </selector>
在layout XML中使用,

点击(此处)折叠或打开

  1. <ImageButton
  2.         android:id="@+id/image_button"
  3.         android:layout_width="wrap_content"
  4.         android:layout_height="wrap_content"
  5.         android:src="@drawable/button_style1"/>
但是边框也被显示出来了,看上去很丑。

网上找了一下,果然有很多人也已经遇到了同样的问题,解决办法有两种:

1.在ImageButton内增加android:background="#00000000"将背景设置为透明,然后指定android:src="@drawable/button_style1";
2.直接指定background,如android:background="@drawable/button_style";
虽然方法2能达到效果,但我个人觉得方法1更符合逻辑。
阅读(1564) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~