Last active
November 12, 2021 22:36
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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... | |
} |
I'm glad I could help! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!