S
S
Sergey2015-11-03 08:39:15
Java
Sergey, 2015-11-03 08:39:15

How can I change the color of a button programmatically?

The default style is light. Those. gray button. I would like to programmatically change the color on the button, for example, to # 1cd000. Because in the visual editor, I just type #1cd000 into backgroundTint and the button turns green without losing its shape (unlike setting the color to background). How to implement this in code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-03
@goodwin74

Found a solution on a foreign site. Here's the code if anyone needs it:

findViewById(R.id.button2).getBackground().setColorFilter(Color.parseColor("#1cd000"), PorterDuff.Mode.MULTIPLY);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question