当前位置: 首页>>代码示例>>Java>>正文


Java ColorStateList.getColorForState方法代码示例

本文整理汇总了Java中android.content.res.ColorStateList.getColorForState方法的典型用法代码示例。如果您正苦于以下问题:Java ColorStateList.getColorForState方法的具体用法?Java ColorStateList.getColorForState怎么用?Java ColorStateList.getColorForState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.res.ColorStateList的用法示例。


在下文中一共展示了ColorStateList.getColorForState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: adaptBackgroundColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
/**
 * Adapts the background color of a tab.
 *
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}. The view may not be null
 * @param viewHolder
 *         The view holder, which stores references to the tab's views, as an instance of the
 *         class {@link PhoneTabViewHolder}. The view holder may not be null
 * @param tab
 *         The tab, whose background color should be adapted, as an instance of the class {@link
 *         Tab}. The tab may not be null
 */
private void adaptBackgroundColor(@NonNull final View view,
                                  @NonNull final PhoneTabViewHolder viewHolder,
                                  @NonNull final Tab tab) {
    ColorStateList colorStateList =
            tab.getBackgroundColor() != null ? tab.getBackgroundColor() :
                    model.getTabBackgroundColor();
    int color = tabBackgroundColor;

    if (colorStateList != null) {
        int[] stateSet =
                model.getSelectedTab() == tab ? new int[]{android.R.attr.state_selected} :
                        new int[]{};
        color = colorStateList.getColorForState(stateSet, colorStateList.getDefaultColor());
    }

    Drawable background = view.getBackground();
    background.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
    Drawable border = viewHolder.borderView.getBackground();
    border.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:34,代码来源:PhoneRecyclerAdapter.java

示例2: getSelectedColorFromStyle

import android.content.res.ColorStateList; //导入方法依赖的package包/类
private int getSelectedColorFromStyle(Context context) {
    int[] textAttrs = {android.R.attr.textColor};
    int[] selectedColorAttrs = {android.R.attr.state_selected};
    
    final TypedArray ta = context.obtainStyledAttributes(itemTextAppearance, textAttrs);
    int colorSelected = -1;
    try {
        ColorStateList textColors = ta.getColorStateList(0);
        if (null != textColors) {
            colorSelected = textColors.getColorForState(selectedColorAttrs, 0);
        }
    } finally {
        ta.recycle();
    }
    return colorSelected;
}
 
开发者ID:ImDobyDad,项目名称:SingleSelectBar,代码行数:17,代码来源:SingleSelectBar.java

示例3: adaptAddTabButtonColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:16,代码来源:TabletTabRecyclerAdapter.java

示例4: TouchableUrlSpan

import android.content.res.ColorStateList; //导入方法依赖的package包/类
public TouchableUrlSpan(String url,
                        ColorStateList textColor,
                        int pressedBackgroundColor) {
    super(url);
    this.normalTextColor = textColor.getDefaultColor();
    this.pressedTextColor = textColor.getColorForState(STATE_PRESSED, normalTextColor);
    this.pressedBackgroundColor = pressedBackgroundColor;
}
 
开发者ID:PaulKlinger,项目名称:Sprog-App,代码行数:9,代码来源:TouchableUrlSpan.java

示例5: MarkerDrawable

import android.content.res.ColorStateList; //导入方法依赖的package包/类
public MarkerDrawable(@NonNull ColorStateList tintList, int closedSize) {
    super(tintList);
    mInterpolator = new AccelerateDecelerateInterpolator();
    mClosedStateSize = closedSize;
    mStartColor = tintList.getColorForState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, tintList.getDefaultColor());
    mEndColor = tintList.getDefaultColor();

}
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:9,代码来源:MarkerDrawable.java

示例6: adaptBackgroundColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
/**
 * Adapts the background color of a tab.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, whose background should be adapted, as an
 *         instance of the class {@link TabItem}. The tab item may not be null
 */
private void adaptBackgroundColor(@NonNull final TabItem tabItem) {
    Tab tab = tabItem.getTab();
    ColorStateList colorStateList = style.getTabBackgroundColor(tab);
    int[] stateSet = model.getSelectedTab() == tab ? new int[]{android.R.attr.state_selected} :
            new int[]{};
    int color = colorStateList.getColorForState(stateSet, colorStateList.getDefaultColor());
    View view = tabItem.getView();
    Drawable background = view.getBackground();
    background.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
    onAdaptBackgroundColor(color, tabItem);
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:19,代码来源:AbstractTabRecyclerAdapter.java

示例7: setBgData

import android.content.res.ColorStateList; //导入方法依赖的package包/类
/**
 * 设置按钮的背景色(只支持纯色,不支持 Bitmap 或 Drawable)
 */
public void setBgData(@Nullable ColorStateList colors) {
    if (hasNativeStateListAPI()) {
        super.setColor(colors);
    } else {
        mFillColors = colors;
        final int currentColor;
        if (colors == null) {
            currentColor = Color.TRANSPARENT;
        } else {
            currentColor = colors.getColorForState(getState(), 0);
        }
        setColor(currentColor);
    }
}
 
开发者ID:coopese,项目名称:qmui,代码行数:18,代码来源:QMUIRoundButtonDrawable.java

示例8: createTintFilter

import android.content.res.ColorStateList; //导入方法依赖的package包/类
private static PorterDuffColorFilter createTintFilter(ColorStateList tint,
                                                      PorterDuff.Mode tintMode, final int[] state) {
    if (tint == null || tintMode == null) {
        return null;
    }
    final int color = tint.getColorForState(state, Color.TRANSPARENT);
    return getPorterDuffColorFilter(color, tintMode);
}
 
开发者ID:ximsfei,项目名称:Android-skin-support,代码行数:9,代码来源:SkinCompatDrawableManager.java

示例9: setBorderTint

import android.content.res.ColorStateList; //导入方法依赖的package包/类
void setBorderTint(ColorStateList tint) {
  if (tint != null) {
    mCurrentBorderTintColor = tint.getColorForState(getState(), mCurrentBorderTintColor);
  }
  mBorderTint = tint;
  mInvalidateShader = true;
  invalidateSelf();
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:9,代码来源:CircularBorderDrawable.java

示例10: setColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
public void setColor(@NonNull ColorStateList tintStateList) {
    int defaultColor = tintStateList.getDefaultColor();
    mFocusedColor = tintStateList.getColorForState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, defaultColor);
    mPressedColor = tintStateList.getColorForState(new int[]{android.R.attr.state_enabled, android.R.attr.state_pressed}, defaultColor);
    mDisabledColor = tintStateList.getColorForState(new int[]{-android.R.attr.state_enabled}, defaultColor);

    //The ripple should be partially transparent
    mFocusedColor = getModulatedAlphaColor(130, mFocusedColor);
    mPressedColor = getModulatedAlphaColor(130, mPressedColor);
    mDisabledColor = getModulatedAlphaColor(130, mDisabledColor);
}
 
开发者ID:zacharee,项目名称:SliderPreferenceEmbedded,代码行数:12,代码来源:AlmostRippleDrawable.java

示例11: getDisabledColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
private int getDisabledColor(ColorStateList colorStateList) {
    return colorStateList.getColorForState(new int[]{-android.R.attr.state_enabled}, 0);
}
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:4,代码来源:CircularProgressButton.java

示例12: getPressedColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
private int getPressedColor(ColorStateList colorStateList) {
    return colorStateList.getColorForState(new int[]{android.R.attr.state_pressed}, 0);
}
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:4,代码来源:CircularProgressButton.java

示例13: init

import android.content.res.ColorStateList; //导入方法依赖的package包/类
private void init() {
    mSolidColor = 0;
    mSelectionDivider = getResources().getDrawable(R.drawable.numberpicker_selection_divider);

    mSelectionDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDER_HEIGHT, getResources().getDisplayMetrics());
    mSelectionDividersDistance = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, UNSCALED_DEFAULT_SELECTION_DIVIDERS_DISTANCE, getResources().getDisplayMetrics());

    mMinHeight = SIZE_UNSPECIFIED;

    mMaxHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, getResources().getDisplayMetrics());
    if (mMinHeight != SIZE_UNSPECIFIED && mMaxHeight != SIZE_UNSPECIFIED && mMinHeight > mMaxHeight) {
        throw new IllegalArgumentException("minHeight > maxHeight");
    }

    mMinWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, getResources().getDisplayMetrics());

    mMaxWidth = SIZE_UNSPECIFIED;
    if (mMinWidth != SIZE_UNSPECIFIED && mMaxWidth != SIZE_UNSPECIFIED && mMinWidth > mMaxWidth) {
        throw new IllegalArgumentException("minWidth > maxWidth");
    }

    mComputeMaxWidth = (mMaxWidth == SIZE_UNSPECIFIED);

    mVirtualButtonPressedDrawable = getResources().getDrawable(R.drawable.item_background_holo_light);

    mPressedStateHelper = new PressedStateHelper();

    setWillNotDraw(false);

    mInputText = new TextView(getContext());
    addView(mInputText);
    mInputText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mInputText.setGravity(Gravity.CENTER);
    mInputText.setSingleLine(true);
    mInputText.setBackgroundResource(0);
    mInputText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);

    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity() / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mTextSize = (int) mInputText.getTextSize();

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextAlign(Align.CENTER);
    paint.setTextSize(mTextSize);
    paint.setTypeface(mInputText.getTypeface());
    ColorStateList colors = mInputText.getTextColors();
    int color = colors.getColorForState(ENABLED_STATE_SET, Color.WHITE);
    paint.setColor(color);
    mSelectorWheelPaint = paint;

    mFlingScroller = new Scroller(getContext(), null, true);
    mAdjustScroller = new Scroller(getContext(), new DecelerateInterpolator(2.5f));

    updateInputTextView();
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:59,代码来源:NumberPicker.java

示例14: setDayOfWeekTextColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
void setDayOfWeekTextColor(ColorStateList dayOfWeekTextColor) {
    final int enabledColor = dayOfWeekTextColor.getColorForState(ENABLED_STATE_SET, 0);
    mDayOfWeekPaint.setColor(enabledColor);
    invalidate();
}
 
开发者ID:Gericop,项目名称:DateTimePicker,代码行数:6,代码来源:SimpleMonthView.java

示例15: getFocusedColor

import android.content.res.ColorStateList; //导入方法依赖的package包/类
private int getFocusedColor(ColorStateList colorStateList) {
    return colorStateList.getColorForState(new int[]{android.R.attr.state_focused}, 0);
}
 
开发者ID:fergus825,项目名称:SmartOrnament,代码行数:4,代码来源:CircularProgressButton.java


注:本文中的android.content.res.ColorStateList.getColorForState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。