高亮显示一个按钮时,pressed无需使用两个绘制? [英] Highlight a button when it pressed without using two drawable?

查看:148
本文介绍了高亮显示一个按钮时,pressed无需使用两个绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我使用两个绘制时,其中一个按钮的状态为pressed和另一另一个为默认值。所以我制作一个洞新形象只是为了简单的效果!所以,现在我问...

before I use two drawable one when the button state is pressed and an another another as default. so I'm fabricating a hole new image just for simple effect ! So now I'm asking...

,才有可能,便可立即上时该按钮是pressed按钮可拉伸(一个滤色器或任何效果)?

is it possible to applicate (a color filter or any effect) on the button drawable when that button is pressed ?

推荐答案

我发现做到这一点的最好办法!

I found the best way to do it !

Drawable drawableNotPressed = button. 
        Drawable drawable = drawableNotPressed.getCurrent();
//use a filter 
        drawable.setColorFilter(0xF00, Mode.MULTIPLY);
        StateListDrawable listDrawable = new StateListDrawable();
        listDrawable.addState(new int[] {android.R.attr.state_pressed}, drawable);
        listDrawable.addState(new int[] { android.R.attr.defaultValue}, drawableNotPressed );
        button.setBackgroundDrawable(listDrawable);

等瞧!

这篇关于高亮显示一个按钮时,pressed无需使用两个绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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