控件按钮的点击效果

手机上按钮通常点击时显示一种效果,没有点击时是另一种效果,这也是默认的情况。但是如果你使用图片按钮,并把背景色设成#00000000后,点击后的效果就看不到了,对于用户来说很不友好,所以你需要做一些修改:使用两张图片,一张是正常显示,一张是点击后的效果。这也是为什么打开别人的res文件夹后总会看到相同前缀名的图片资源的原因。

下面说一下怎么实现的:
1.新建一个drawable文件夹,拷贝icon_play_prev_normal.png和icon_play_prev_pressed.png两张图片进去。
2.还在上面的文件夹中编写icon_play_prev.xml该文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/icon_play_prev_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/icon_play_prev_normal"/>

</selector>


3.在layout文件夹中编写需要的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background" >

    <ImageButton
        android:background="#00000000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/icon_play_prev" />

</RelativeLayout>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值