Beispiel #1
0
  public static int applyLabelColor(Label label, TextView view) {
    int bgColorRgb = U.decodeLabelBackgroundColor(label.backgroundColor);
    if (bgColorRgb == -1) {
      bgColorRgb = 0x212121; // default color Grey 900
    }

    GradientDrawable grad = null;

    Drawable bg = view.getBackground();
    if (bg instanceof GradientDrawable) {
      grad = (GradientDrawable) bg;
    } else if (bg instanceof StateListDrawable) {
      StateListDrawable states = (StateListDrawable) bg;
      Drawable current = states.getCurrent();
      if (current instanceof GradientDrawable) {
        grad = (GradientDrawable) current;
      }
    }
    if (grad != null) {
      grad.setColor(0xff000000 | bgColorRgb);
      final int labelColor =
          0xff000000 | U.getLabelForegroundColorBasedOnBackgroundColor(bgColorRgb);
      view.setTextColor(labelColor);
      return labelColor;
    }
    return 0;
  }