Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Created October 9, 2017 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssaurel/75607ef6970d969fd31fb6d579a3f31e to your computer and use it in GitHub Desktop.
Save ssaurel/75607ef6970d969fd31fb6d579a3f31e to your computer and use it in GitHub Desktop.
ApplyColor method for a tutorial on the SSaurel's Blog
private void applyColor(String hexaTime) {
int color = Color.parseColor(hexaTime);
root.setBackgroundColor(color);
// white or black color for the text view
int tmp = (int) (0.2126 * Color.red(color)) + (int) (0.7152 * Color.green(color)) + (int) (0.0722 * Color.blue(color));
timeTv.setText(hexaTime);
timeTv.setTextColor(tmp < 128 ? Color.WHITE : Color.BLACK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment