Java Code Examples for android.content.res.ColorStateList

The following examples show how to use android.content.res.ColorStateList. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Android-Skin   Source File: MyApp.java    License: MIT License 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // SpInstance.getInstance().init(getApplicationContext(),"skin_sp_file",false);
    AndroidSkin.getInstance().init(this);
    AndroidSkin.getInstance().addCustomAttrSupport(R.attr.tv_border_color,
        new ICustAttrApplyForColorListener<TestView>() {

            @Override
            public void applyColor(int attrId, TestView view, ColorStateList color) {
                view.setBorderColor(color.getDefaultColor());
            }
        });
    AndroidSkin.getInstance().addCustomAttrSupport(R.attr.tv_drawable_left_and_right,
        new TestViewDrawableLRListener());
}
 
Example 2
Source Project: UIWidget   Source File: RadiusTextDelegate.java    License: Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private ColorStateList getColorSelector(int normalColor, int pressedColor, int disabledColor, int selectedColor, int checkedColor) {
    return new ColorStateList(
            new int[][]{
                    new int[]{mStatePressed},
                    new int[]{mStateSelected},
                    new int[]{mStateChecked},
                    new int[]{mStateDisabled},
                    new int[]{}
            },
            new int[]{
                    pressedColor,
                    selectedColor,
                    checkedColor,
                    disabledColor,
                    normalColor
            }
    );
}
 
Example 3
Source Project: IdeaTrackerPlus   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
private void changeSecondaryColor() {

        //disable search mode for tabLayout
        disableSearchMode();

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);

        tabLayout.setSelectedTabIndicatorColor(mSecondaryColor);
        mFab.setBackgroundTintList(ColorStateList.valueOf(mSecondaryColor));

        if (rightDrawer != null) {
            mColorItem2.withIconColor(mSecondaryColor);
            rightDrawer.updateItem(mColorItem2);
        }

        RecyclerOnClickListener.setSecondaryColor(mSecondaryColor);
    }
 
Example 4
Source Project: HeroVideo-master   Source File: VideoDetailsActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void loadData() {

    RetrofitHelper.getBiliAppAPI()
            .getVideoDetails(av)
            .compose(this.bindToLifecycle())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(videoDetails -> {

                mVideoDetailsInfo = videoDetails.getData();
                LogUtil.test(" VideoDetails finishTask" + mVideoDetailsInfo.getTitle());
                finishTask();
            }, throwable -> {

                mFAB.setClickable(false);
                mFAB.setBackgroundTintList(ColorStateList.valueOf(
                        getResources().getColor(R.color.gray_20)));
            });
}
 
Example 5
Source Project: react-native-GPay   Source File: ReactTextInputPropertyTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testPlaceholderTextColor() {
  ReactEditText view = mManager.createViewInstance(mThemedContext);

  final ColorStateList defaultPlaceholderColorStateList =
      DefaultStyleValuesUtil.getDefaultTextColorHint(
          view.getContext());

  ColorStateList colors = view.getHintTextColors();
  assertThat(colors).isEqualTo(defaultPlaceholderColorStateList);

  mManager.updateProperties(view, buildStyles("placeholderTextColor", null));
  colors = view.getHintTextColors();
  assertThat(colors).isEqualTo(defaultPlaceholderColorStateList);

  mManager.updateProperties(view, buildStyles("placeholderTextColor", Color.RED));
  colors = view.getHintTextColors();
  assertThat(colors.getDefaultColor()).isEqualTo(Color.RED);

  mManager.updateProperties(view, buildStyles("placeholderTextColor", null));
  colors = view.getHintTextColors();
  assertThat(colors).isEqualTo(defaultPlaceholderColorStateList);
}
 
Example 6
private CalendarItemStyle(
    ColorStateList backgroundColor,
    ColorStateList textColor,
    ColorStateList strokeColor,
    int strokeWidth,
    ShapeAppearanceModel itemShape,
    @NonNull Rect insets) {
  Preconditions.checkArgumentNonnegative(insets.left);
  Preconditions.checkArgumentNonnegative(insets.top);
  Preconditions.checkArgumentNonnegative(insets.right);
  Preconditions.checkArgumentNonnegative(insets.bottom);

  this.insets = insets;
  this.textColor = textColor;
  this.backgroundColor = backgroundColor;
  this.strokeColor = strokeColor;
  this.strokeWidth = strokeWidth;
  this.itemShape = itemShape;
}
 
Example 7
Source Project: MaterialChipsInput   Source File: DetailedChipView.java    License: Apache License 2.0 5 votes vote down vote up
private static DetailedChipView newInstance(Builder builder) {
    DetailedChipView detailedChipView = new DetailedChipView(builder.context);
    // avatar
    if(builder.avatarUri != null)
        detailedChipView.setAvatarIcon(builder.avatarUri);
    else if(builder.avatarDrawable != null)
        detailedChipView.setAvatarIcon(builder.avatarDrawable);
    else
        detailedChipView.setAvatarIcon(mLetterTileProvider.getLetterTile(builder.name));

    // background color
    if(builder.backgroundColor != null)
        detailedChipView.setBackGroundcolor(builder.backgroundColor);

    // text color
    if(builder.textColor != null)
        detailedChipView.setTextColor(builder.textColor);
    else if(ColorUtil.isColorDark(detailedChipView.getBackgroundColor()))
        detailedChipView.setTextColor(ColorStateList.valueOf(Color.WHITE));
    else
        detailedChipView.setTextColor(ColorStateList.valueOf(Color.BLACK));

    // delete icon color
    if(builder.deleteIconColor != null)
        detailedChipView.setDeleteIconColor(builder.deleteIconColor);
    else if(ColorUtil.isColorDark(detailedChipView.getBackgroundColor()))
        detailedChipView.setDeleteIconColor(ColorStateList.valueOf(Color.WHITE));
    else
        detailedChipView.setDeleteIconColor(ColorStateList.valueOf(Color.BLACK));

    detailedChipView.setName(builder.name);
    detailedChipView.setInfo(builder.info);
    return detailedChipView;
}
 
Example 8
Source Project: appinventor-extensions   Source File: ButtonBase.java    License: Apache License 2.0 5 votes vote down vote up
private ColorStateList createRippleState () {

    int[][] states = new int[][] { new int[] { android.R.attr.state_enabled} };
    int enabled_color = defaultColorStateList.getColorForState(view.getDrawableState(), android.R.attr.state_enabled);
    int[] colors = new int[] { Color.argb(70, Color.red(enabled_color), Color.green(enabled_color),
            Color.blue(enabled_color)) };

    return new ColorStateList(states, colors);
  }
 
Example 9
Source Project: ChromeLikeTabSwitcher   Source File: TabSwitcherStyle.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the background color of tabs.
 *
 * @param tab
 *         The tab, the background color should be returned for, as an instance of the class
 *         {@link Tab} or null, if the background color should not be returned for a specific
 *         tab
 * @return The background color of tabs as an instance of the class {@link ColorStateList}
 */
public final ColorStateList getTabBackgroundColor(@Nullable final Tab tab) {
    ColorStateList colorStateList = tab != null ? tab.getBackgroundColor() : null;

    if (colorStateList == null) {
        colorStateList = model.getTabBackgroundColor();

        if (colorStateList == null) {
            colorStateList = themeHelper.getColorStateList(tabSwitcher.getLayout(),
                    R.attr.tabSwitcherTabBackgroundColor);
        }
    }

    return colorStateList;
}
 
Example 10
Source Project: NoHttp   Source File: ResCompat.java    License: Apache License 2.0 5 votes vote down vote up
public static ColorStateList getColorStateList(int colorStateId, Theme theme) {
    Resources resources = NoHttp.getContext().getResources();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        return resources.getColorStateList(colorStateId, theme);
    else
        return resources.getColorStateList(colorStateId);
}
 
Example 11
/**
 * Sets color state list as background for this button.
 * <p/>
 * Xml attribute: {@code app:floatingActionButtonColor}
 *
 * @param colorStateList color
 */
public void setColorStateList(ColorStateList colorStateList) {
    boolean changed = mColorStateList != colorStateList;

    mColorStateList = colorStateList;

    if (changed) {
        updateBackground();
    }
}
 
Example 12
Source Project: Mover   Source File: RippleDrawable.java    License: Apache License 2.0 5 votes vote down vote up
public static RippleDrawable makeFor(View target, ColorStateList colors, boolean parentIsScrollContainer){
    RippleDrawable drawable = new RippleDrawable(colors, target.getBackground());

    TouchTracker tracker = new TouchTracker();
    tracker.setInsideScrollContainer(parentIsScrollContainer);

    ViewUtils.setBackground(target, drawable);
    target.setOnTouchListener(tracker);

    return drawable;
}
 
Example 13
private void setupFabs() {
    if(TRUE.equalsIgnoreCase(postItem.getLikes())){
        upFab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_green700)));
    }else if(FALSE.equalsIgnoreCase(postItem.getLikes())){
        downFab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_red700)));
    }else{
        upFab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_bluegrey900)));
        downFab.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_bluegrey900)));
    }
}
 
Example 14
@Override
public void setIconTintList(ColorStateList tintList) {
    mExpandDrawable = DrawableCompat.wrap(mExpandDrawable
            .getConstantState().newDrawable()).mutate();
    DrawableCompat.setTintList(mExpandDrawable, tintList);

    mCollapseDrawable = DrawableCompat.wrap(mCollapseDrawable
            .getConstantState().newDrawable()).mutate();
    DrawableCompat.setTintList(mCollapseDrawable, tintList);

    super.setIconTintList(tintList);
}
 
Example 15
/**
 * Adapts the color of a button, which allows to add a new tab.
 *
 * @param addTabItem
 *         The add tab item, which corresponds to the button, whose color should be adapted, as
 *         an instance of the class {@link AddTabItem}. The add tab item may not be null
 */
private void adaptAddTabButtonColor(@NonNull final AddTabItem addTabItem) {
    ColorStateList colorStateList = getStyle().getAddTabButtonColor();
    int[] stateSet = new int[]{};
    int color = colorStateList.getColorForState(stateSet, colorStateList.getDefaultColor());
    View view = addTabItem.getView();
    Drawable background = view.getBackground();
    background.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
 
Example 16
/**
 * Checks that the {@link MaterialRadioButton} buttonTint matches {@link
 * R.color#radiobutton_themeable_attribute_color}.
 */
static void testThemeableButtonTint(RadioButton radioButton) {
  ColorStateList buttonTintList = CompoundButtonCompat.getButtonTintList(radioButton);
  assertThat(buttonTintList.getColorForState(STATE_CHECKED, Color.BLACK))
      .isEqualTo(MaterialColors.getColor(radioButton, R.attr.colorControlActivated));
  assertThat(buttonTintList.getColorForState(STATE_UNCHECKED, Color.BLACK))
      .isEqualTo(MaterialColors.getColor(radioButton, R.attr.colorOnSurface));
}
 
Example 17
public ColorStateList build(){
    SpeedyArrayMap<int[], Integer> speedyArrayMap = mColorStateList.copy();
    speedyArrayMap.put(mDefaultStateSet,mDefaultStateColor);
    int size = speedyArrayMap.size();
    int[][] stateSet = new int[size][];
    int [] colors = new int[size];
    for (int index=0;index<size;index++){
        stateSet[index] = speedyArrayMap.keyAt(index);
        colors[index] = speedyArrayMap.valueAt(index);
    }
    return new ColorStateList(stateSet,colors);
}
 
Example 18
Source Project: ProjectX   Source File: DotDrawable.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
private PorterDuffColorFilter getTintFilter(@Nullable ColorStateList tint,
                                            @Nullable PorterDuff.Mode tintMode,
                                            int defaultColor) {
    return tint == null || tintMode == null ? null : new PorterDuffColorFilter(
            tint.getColorForState(getState(), defaultColor), tintMode);
}
 
Example 19
Source Project: ChromeLikeTabSwitcher   Source File: TabSwitcherStyle.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the color of the button, which allows to add a new tab. When using the smartphone
 * layout, such a button is never shown. When using the tablet layout, the button is shown next
 * to the tabs.
 *
 * @return The color of the button, which allows to add a new tab, as an instance of the class
 * {@link ColorStateList} or null, if the default color is used
 */
public final ColorStateList getAddTabButtonColor() {
    ColorStateList colorStateList = model.getAddTabButtonColor();

    if (colorStateList == null) {
        colorStateList = themeHelper.getColorStateList(tabSwitcher.getLayout(),
                R.attr.tabSwitcherAddTabButtonColor);
    }

    return colorStateList;
}
 
Example 20
private void setTextColor(ColorStateList color) {
	if (null != mHeaderText) {
		mHeaderText.setTextColor(color);
	}
	if (null != mSubHeaderText) {
		mSubHeaderText.setTextColor(color);
	}
}
 
Example 21
private void setTextColor(ColorStateList color) {
	if (null != mHeaderText) {
		mHeaderText.setTextColor(color);
	}
	if (null != mSubHeaderText) {
		mSubHeaderText.setTextColor(color);
	}
}
 
Example 22
Source Project: kAndroid   Source File: KChartTabView.java    License: Apache License 2.0 5 votes vote down vote up
public void setTextColor(ColorStateList color) {
    mColorStateList = color;
    for (int i = 0; i < mLlContainer.getChildCount(); i++) {
        TabView tabView = (TabView) mLlContainer.getChildAt(i);
        tabView.setTextColor(mColorStateList);
    }
    if (mColorStateList != null) {
        mTvFullScreen.setTextColor(mColorStateList);
    }
}
 
Example 23
ErrorViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
    errorTextView.setText(R.string.load_comments_failed);
    errorTextView.setTextColor(mSecondaryTextColor);
    retryButton.setOnClickListener(view -> mRetryLoadingMoreCallback.retryLoadingMore());
    retryButton.setBackgroundTintList(ColorStateList.valueOf(mColorPrimaryLightTheme));
    retryButton.setTextColor(mButtonTextColor);
}
 
Example 24
Source Project: CommonUtils   Source File: MenuItemsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull MenuItemsAdapter.ViewHolder holder, int position) {
    final BaseDrawerItem<E> item = items.get(position);

    holder.icon.setImageResource(item.icon);
    holder.name.setText(item.name);

    if (item.badgeNumber >= 0) {
        holder.badge.setVisibility(View.VISIBLE);
        holder.badge.setText(String.valueOf(item.badgeNumber));
    } else {
        holder.badge.setVisibility(View.GONE);
    }

    holder.itemView.setOnClickListener(v -> {
        if (listener != null) listener.onMenuItemSelected(item);
    });

    if (item.active) {
        holder.name.setTextColor(colorAccent);
        holder.itemView.setBackgroundResource(R.drawable.item_drawer_active);
        holder.icon.setImageTintList(ColorStateList.valueOf(colorAccent));
    } else {
        holder.name.setTextColor(colorTextPrimary);
        holder.icon.setImageTintList(ColorStateList.valueOf(colorTextPrimary));
        CommonUtils.setBackground(holder.itemView, android.R.attr.selectableItemBackground);
    }

    if (width > 0) {
        holder.itemView.getLayoutParams().width = width;
        holder.itemView.requestLayout();
    }
}
 
Example 25
private Drawable getMessageSelector(@ColorInt int normalColor, @ColorInt int selectedColor, @ColorInt int pressedColor, @DrawableRes int shape) {
    Drawable drawable = DrawableCompat.wrap(getVectorDrawable(shape)).mutate();
    DrawableCompat.setTintList(
            drawable,
            new ColorStateList(
                    new int[][]{
                            new int[]{android.R.attr.state_selected},
                            new int[]{android.R.attr.state_pressed},
                            new int[]{-android.R.attr.state_pressed, -android.R.attr.state_selected}
                    },
                    new int[]{selectedColor, pressedColor, normalColor}
            ));
    return drawable;
}
 
Example 26
Source Project: a   Source File: NavigationViewUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void setItemIconColors(@NonNull NavigationView navigationView, @ColorInt int normalColor, @ColorInt int selectedColor) {
    final ColorStateList iconSl = new ColorStateList(
            new int[][]{
                    new int[]{-android.R.attr.state_checked},
                    new int[]{android.R.attr.state_checked}
            },
            new int[]{
                    normalColor,
                    selectedColor
            });
    navigationView.setItemIconTintList(iconSl);
}
 
Example 27
@Override
public void setIconTintList(ColorStateList tintList) {
    mExpandDrawable = DrawableCompat.wrap(mExpandDrawable
            .getConstantState().newDrawable()).mutate();
    DrawableCompat.setTintList(mExpandDrawable, tintList);

    mCollapseDrawable = DrawableCompat.wrap(mCollapseDrawable
            .getConstantState().newDrawable()).mutate();
    DrawableCompat.setTintList(mCollapseDrawable, tintList);

    super.setIconTintList(tintList);
}
 
Example 28
Source Project: ClipCircleHeadLikeQQ   Source File: RoundedImageView.java    License: Apache License 2.0 5 votes vote down vote up
public void setBorderColor(ColorStateList colors) {
  if (mBorderColor.equals(colors)) { return; }

  mBorderColor =
      (colors != null) ? colors : ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
  updateDrawableAttrs();
  updateBackgroundDrawableAttrs(false);
  if (mBorderWidth > 0) {
    invalidate();
  }
}
 
Example 29
Source Project: NightOwl   Source File: TabLayoutHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object[] setup(@NonNull View view, @NonNull TypedArray a, int attr) {
    TabLayout tabLayout = (TabLayout) view;
    ColorStateList csl1 = tabLayout.getTabTextColors();
    ColorStateList csl2 = a.getColorStateList(attr);
    return new ColorStateList[]{ csl1, csl2 };
}
 
Example 30
Source Project: TextLayoutBuilder   Source File: TextLayoutBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the text color for the layout.
 *
 * @param colorStateList The text color state list for the layout
 * @return This {@link TextLayoutBuilder} instance
 */
public TextLayoutBuilder setTextColor(ColorStateList colorStateList) {
  mParams.createNewPaintIfNeeded();
  mParams.color = colorStateList;
  mParams.paint.setColor(mParams.color != null ? mParams.color.getDefaultColor() : Color.BLACK);
  mSavedLayout = null;
  return this;
}