user12251399
user12251399

Reputation:

How to get color from buttons?

I need to find the red buttons on Activity and set orange background color to these buttons.

When I click on the button I set it to red:

view.setBackgroundTintList(ColorStateList.valueOf(Color.RED));

When I click on another button, the red buttons should turn orange.

public void Active(View view){
    for (View but : buttons) {
        but.setClickable(true);
            but.setBackgroundTintList();
    }
}

I do not know how to get the id of the colors

Upvotes: 1

Views: 100

Answers (2)

Skizo-ozᴉʞS ツ
Skizo-ozᴉʞS ツ

Reputation: 20616

For me is unclear your question but I'll try to answer it.

Supposing buttons is a List<Button>, so what you can do is.

for(View but : buttons){
  int color = ((ColorDrawable)but.getBackground()).getColor();
  if(color == Color.Red){
    //This button is red change it to orange
    but.setBackgroundColor(R.colors.orange);
  }
}

And when you are clicking the button use

button.setBackgroundResource(Color.Red);

Upvotes: 1

Djaf
Djaf

Reputation: 256

but.setBackgroundColor(Color.RED);

use that

Upvotes: 0

Related Questions