android 按鈕點擊效果實現


在其他人的博客里看到其實實現按鈕點擊效果的方法有很多,這里提到的只是其中一個辦法

圖片素材(我自己用截圖截的,可以自己搞)

放到mipmap目錄下(studio是在這個目錄下 , eclipse 直接放在drawable下)

在drawable目錄下創建一個btn_select.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false"
        android:drawable="@mipmap/black"/>
    <item android:state_pressed="true"
        android:drawable="@mipmap/blue"/>
</selector>

在布局的時候用background調用該文件就行了

調用方法:

 <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:background="@drawable/btn_selector"
        android:layout_above="@+id/button2"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="113dp" />

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM