コード例 #1
0
  static StateListDrawable bootstrapDropDownArrow(
      Context context,
      int width,
      int height,
      ExpandDirection expandDirection,
      boolean outline,
      BootstrapBrand brand) {
    StateListDrawable stateListDrawable = new StateListDrawable();

    int defaultColor = outline ? brand.defaultFill(context) : brand.defaultTextColor(context);
    int activeColor =
        outline
            ? ColorUtils.resolveColor(android.R.color.white, context)
            : brand.activeTextColor(context);
    int disabledColor = outline ? brand.disabledFill(context) : brand.disabledTextColor(context);

    if (Build.VERSION.SDK_INT >= 14) {
      stateListDrawable.addState(
          new int[] {android.R.attr.state_hovered},
          createArrowIcon(context, width, height, activeColor, expandDirection));
    }

    stateListDrawable.addState(
        new int[] {android.R.attr.state_activated},
        createArrowIcon(context, width, height, activeColor, expandDirection));
    stateListDrawable.addState(
        new int[] {android.R.attr.state_focused},
        createArrowIcon(context, width, height, activeColor, expandDirection));
    stateListDrawable.addState(
        new int[] {android.R.attr.state_pressed},
        createArrowIcon(context, width, height, activeColor, expandDirection));
    stateListDrawable.addState(
        new int[] {android.R.attr.state_selected},
        createArrowIcon(context, width, height, activeColor, expandDirection));
    stateListDrawable.addState(
        new int[] {-android.R.attr.state_enabled},
        createArrowIcon(context, width, height, disabledColor, expandDirection));
    stateListDrawable.addState(
        new int[] {}, createArrowIcon(context, width, height, defaultColor, expandDirection));
    return stateListDrawable;
  }
コード例 #2
0
  /**
   * Generates a colorstatelist for a bootstrap button
   *
   * @param context the current context
   * @param outline whether the button is outlined
   * @param brand the button brand
   * @return the color state list
   */
  static ColorStateList bootstrapButtonText(
      Context context, boolean outline, BootstrapBrand brand) {

    int defaultColor = outline ? brand.defaultFill(context) : brand.defaultTextColor(context);
    int activeColor =
        outline
            ? ColorUtils.resolveColor(android.R.color.white, context)
            : brand.activeTextColor(context);
    int disabledColor = outline ? brand.disabledFill(context) : brand.disabledTextColor(context);

    if (outline && brand instanceof DefaultBootstrapBrand) { // special case
      DefaultBootstrapBrand db = (DefaultBootstrapBrand) brand;

      if (db == DefaultBootstrapBrand.SECONDARY) {
        defaultColor = ColorUtils.resolveColor(R.color.bootstrap_brand_secondary_border, context);
        disabledColor = defaultColor;
      }
    }
    return new ColorStateList(
        getStateList(), getColorList(defaultColor, activeColor, disabledColor));
  }