How to grey out a button?

后端 未结 9 742
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-22 22:23

I have a button defined as shown below. When I want to disable it I use my_btn.setEnabled(false), but I would also like to grey it out. How can I do that?

9条回答
  •  情歌与酒
    2020-12-22 22:51

    The most easy solution is to set color filter to the background image of a button as I saw here

    You can do as follow:

    if ('need to set button disable')
        button.getBackground().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY);
    else
        button.getBackground().setColorFilter(null);
    

    Hope I helped someone...

提交回复
热议问题