Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodrigoborgesdeoliveira/e3e3045ebba54a7579277f58d0ff3705 to your computer and use it in GitHub Desktop.
Save rodrigoborgesdeoliveira/e3e3045ebba54a7579277f58d0ff3705 to your computer and use it in GitHub Desktop.
Compare if a background of a view in android is equal to a specific resource id
// Comparing to a color
if (Objects.equals(view.getBackground().getConstantState(), activity.getResources().getDrawable(R.color.anyColor).getConstantState())) {
// Do what you have to do...
}
// Comparing to a drawable
if (Objects.equals(view.getBackground().getConstantState(), activity.getResources().getDrawable(R.drawable.anyDrawable).getConstantState())) {
// Do what you have to do...
}
@JumperBot
Copy link

I was searching for such a solution on forums for a day now... I didn't expect that a GitHib Gist has a very helpful answer! Thanks to the contributors!

@rodrigoborgesdeoliveira
Copy link
Author

I'm glad I could help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment