使用自定义颜色按钮的背景,而使用selectableItemBackground属性 [英] using a custom color for button background while using selectableItemBackground attribute

查看:3646
本文介绍了使用自定义颜色按钮的背景,而使用selectableItemBackground属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用

安卓背景=机器人:ATTR / selectableItemBackground

让我的按钮做适当的效果每个Android版本一样荡漾,等等。

to get my button to do appropriate effects for each android version like rippling, etc.

但是,这会产生一个按钮是灰色的,当我需要一个不同的颜色。

But this produces a button with a grey color when I need a different color.

我怎么能覆盖这个默认的颜色?

How can I override this default color ?

推荐答案

而不是使用安卓?ATTR / selectableItemBackground你可以创建一个绘制中的XML文件夹下的内容。     

instead of using ?android:attr/selectableItemBackground you can create a xml in drawable in folder with following content.

<item 
    android:state_pressed="true"
    android:drawable="@color/orange"/>
<item 
    android:state_enabled="false"
    android:drawable="@color/default"/>
<item
    android:drawable="@color/default"/>

</selector>
Updated: so you save this files as : btn_drawable.xml in drawable folder.

Simply replace ?android:attr/selectableItemBackground with *@drawable/btn_drawable.xml*

这篇关于使用自定义颜色按钮的背景,而使用selectableItemBackground属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆