Android點擊按鈕后改變顏色


1、在res文件夾下新建一個文件夾drawable

2、在drawable文件夾下面建立一個xml文件:button_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/normal" android:state_pressed="false"/>
        <item android:drawable="@drawable/pressed" android:state_pressed="true"/>
</selector>

3、在value文件夾下的string.xml文件里添加normal【未選中】和pressed【選中】的樣式

<drawable name="clr_normal">#ff6501</drawable>
<drawable name="clr_pressed">#a44100</drawable>

4、在布局中通過background調用button_selector.xml的樣式

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/login_button_selector"
        />


免責聲明!

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



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