本文整理匯總了Java中android.content.res.ColorStateList.valueOf方法的典型用法代碼示例。如果您正苦於以下問題:Java ColorStateList.valueOf方法的具體用法?Java ColorStateList.valueOf怎麽用?Java ColorStateList.valueOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.ColorStateList
的用法示例。
在下文中一共展示了ColorStateList.valueOf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setChatFragmentFabColorToSharedPrefsValue
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public static void setChatFragmentFabColorToSharedPrefsValue(AppCompatActivity activity)
{
//Grab an instance of SharedPrefs if we haven't already
if (mSharedPreferences == null)
{
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity);
}
if (activity != null)
{
int initialColor = -1;
if (mSharedPreferences.getBoolean("same_fab_color", false))
{
initialColor = mSharedPreferences.getInt("default_color", activity.getResources().getColor(R.color.colorPrimary));
}
else
{
initialColor = mSharedPreferences.getInt("fab_color", activity.getResources().getColor(R.color.colorAccent));
}
ColorStateList colorStateList = ColorStateList.valueOf(initialColor);
tints(colorStateList, activity);
}
}
示例2: tint
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public static void tint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
ColorStateList sl = ColorStateList.valueOf(color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressBar.setProgressTintList(sl);
progressBar.setSecondaryProgressTintList(sl);
if (!skipIndeterminate)
progressBar.setIndeterminateTintList(sl);
} else {
PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
mode = PorterDuff.Mode.MULTIPLY;
}
if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
if (progressBar.getProgressDrawable() != null)
progressBar.getProgressDrawable().setColorFilter(color, mode);
}
}
示例3: generateRippleMaskDrawable
import android.content.res.ColorStateList; //導入方法依賴的package包/類
/**
* 邊界被限製的Ripple, 默認狀態是透明
*/
public static Drawable generateRippleMaskDrawable(int rippleColor) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return null;
}
RippleDrawable drawable = new RippleDrawable(ColorStateList.valueOf(rippleColor), null, new ColorDrawable(rippleColor));
return drawable;
}
示例4: TextConfig
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public TextConfig(TypedArray typedArray) {
DEFAULT_SIZE = IconDotTextView.sDefaultTextSize;
if (typedArray != null) {
mSize = typedArray.getDimensionPixelSize(R.styleable.IconDotTextView_textSize, DEFAULT_SIZE);
mColorStateList = typedArray.getColorStateList(R.styleable.IconDotTextView_textColor);
if (mColorStateList == null) {
mColorStateList = ColorStateList.valueOf(DEFAULT_COLOR);
}
mText = typedArray.getString(R.styleable.IconDotTextView_text);
}
init();
}
示例5: getAdaptiveRippleDrawable
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public static Drawable getAdaptiveRippleDrawable(
int normalColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new RippleDrawable(ColorStateList.valueOf(darker(normalColor)), getRippleMask(normalColor), null);
} else {
return getStateListDrawable(normalColor, darker(normalColor));
}
}
示例6: getSelectableBackgroundCompat
import android.content.res.ColorStateList; //導入方法依賴的package包/類
/**
* Helper to get a custom selectable background with Ripple if device has at least Lollipop.
*
* @param normalColor the color in normal state
* @param pressedColor the pressed color
* @param rippleColor the color of the ripple
* @return the RippleDrawable with StateListDrawable if at least Lollipop, the normal
* StateListDrawable otherwise
* @since 5.0.0-b7 Created
* <br/>5.0.0-rc1 RippleColor becomes the 3rd parameter
*/
public static Drawable getSelectableBackgroundCompat(@ColorInt int normalColor,
@ColorInt int pressedColor,
@ColorInt int rippleColor) {
if (Utils.hasLollipop()) {
return new RippleDrawable(ColorStateList.valueOf(rippleColor),
getStateListDrawable(normalColor, pressedColor),
getRippleMask(normalColor));
} else {
return getStateListDrawable(normalColor, pressedColor);
}
}
示例7: setBorderColor
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public void setBorderColor(ColorStateList colors) {
if (mBorderColor.equals(colors)) {
return;
}
mBorderColor = (colors != null) ? colors : ColorStateList
.valueOf(DEFAULT_BORDER_COLOR);
updateDrawable();
if (mBorderWidth > 0) {
invalidate();
}
}
示例8: onCreate
import android.content.res.ColorStateList; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* Tint the spinner the primary theme color
*/
ProgressBar progressBar = (ProgressBar) findViewById(android.R.id.progress);
int color = ContextCompat.getColor(getContext(), R.color.kOrange);
ColorStateList colorStateList = ColorStateList.valueOf(color);
DrawableCompat.setTintList(progressBar.getIndeterminateDrawable(), colorStateList);
}
示例9: setBorderColor
import android.content.res.ColorStateList; //導入方法依賴的package包/類
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();
}
}
示例10: setChipBackgroundColor
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public void setChipBackgroundColor(@ColorInt int color) {
this.backgroundColor = ColorStateList.valueOf(color);
getChildAt(0).getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
示例11: setMetTextColor
import android.content.res.ColorStateList; //導入方法依賴的package包/類
/**
* Same function as {@link #setTextColor(int)}. (Directly overriding the built-in one could cause some error, so use this method instead.)
*/
public void setMetTextColor(int color) {
textColorStateList = ColorStateList.valueOf(color);
resetTextColor();
}
示例12: setBorderColor
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public RoundedDrawable setBorderColor(ColorStateList colors) {
mBorderColor = colors != null ? colors : ColorStateList.valueOf(0);
mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR));
return this;
}
示例13: SmartTabLayout
import android.content.res.ColorStateList; //導入方法依賴的package包/類
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Disable the Scroll Bar
setHorizontalScrollBarEnabled(false);
final DisplayMetrics dm = getResources().getDisplayMetrics();
final float density = dm.density;
int tabBackgroundResId = NO_ID;
boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
ColorStateList textColors;
float textSize = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
int customTabLayoutId = NO_ID;
int customTabTextViewId = NO_ID;
boolean clickable = TAB_CLICKABLE;
int titleOffset = (int) (TITLE_OFFSET_DIPS * density);
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
tabBackgroundResId = a.getResourceId(
R.styleable.stl_SmartTabLayout_stl_defaultTabBackground, tabBackgroundResId);
textAllCaps = a.getBoolean(
R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
textColors = a.getColorStateList(
R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor);
textSize = a.getDimension(
R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
textHorizontalPadding = a.getDimensionPixelSize(
R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
textMinWidth = a.getDimensionPixelSize(
R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth);
customTabLayoutId = a.getResourceId(
R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, customTabLayoutId);
customTabTextViewId = a.getResourceId(
R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId);
distributeEvenly = a.getBoolean(
R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
clickable = a.getBoolean(
R.styleable.stl_SmartTabLayout_stl_clickable, clickable);
titleOffset = a.getLayoutDimension(
R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset);
a.recycle();
this.titleOffset = titleOffset;
this.tabViewBackgroundResId = tabBackgroundResId;
this.tabViewTextAllCaps = textAllCaps;
this.tabViewTextColors = (textColors != null)
? textColors
: ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR);
this.tabViewTextSize = textSize;
this.tabViewTextHorizontalPadding = textHorizontalPadding;
this.tabViewTextMinWidth = textMinWidth;
this.internalTabClickListener = clickable ? new InternalTabClickListener() : null;
this.distributeEvenly = distributeEvenly;
if (customTabLayoutId != NO_ID) {
setCustomTabView(customTabLayoutId, customTabTextViewId);
}
this.tabStrip = new SmartTabStrip(context, attrs);
if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) {
throw new UnsupportedOperationException(
"'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
}
// Make sure that the Tab Strips fills this View
setFillViewport(!tabStrip.isIndicatorAlwaysInCenter());
addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
示例14: createBackgroundTintColors
import android.content.res.ColorStateList; //導入方法依賴的package包/類
/**
*/
@Nullable
@Override
ColorStateList createBackgroundTintColors(int tintColor) {
return tintColor != Color.TRANSPARENT ? ColorStateList.valueOf(tintColor) : null;
}
示例15: Config
import android.content.res.ColorStateList; //導入方法依賴的package包/類
protected Config(Context context) {
int colorAccent = ColorUtils.getThemeAttrColor(context, R.attr.colorAccent);
mBackgroundColorStateList = ColorStateList.valueOf(colorAccent);
mTextBackgroundDrawable = R.drawable.qav_text_background;
mTextColor = Color.WHITE;
}