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