本文整理汇总了Java中android.graphics.drawable.ColorDrawable.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java ColorDrawable.setColor方法的具体用法?Java ColorDrawable.setColor怎么用?Java ColorDrawable.setColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.ColorDrawable
的用法示例。
在下文中一共展示了ColorDrawable.setColor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBgColor
import android.graphics.drawable.ColorDrawable; //导入方法依赖的package包/类
private static Drawable createBgColor(Context context, @ColorInt int resBackgroundColor, @PressedMode.Mode int mode, @FloatRange(from = 0.0f, to = 1.0f) float alpha) {
ColorDrawable colorDrawableNormal = new ColorDrawable();
ColorDrawable colorDrawablePressed = new ColorDrawable();
ColorDrawable colorDrawableUnable = new ColorDrawable();
colorDrawableNormal.setColor(resBackgroundColor);
colorDrawablePressed.setColor(resBackgroundColor);
colorDrawableUnable.setColor(resBackgroundColor);
Drawable pressed = getPressedStateDrawable(context, mode, alpha, colorDrawablePressed);
Drawable unable = getUnableStateDrawable(context, colorDrawableUnable);
return createStateListDrawable(colorDrawableNormal, pressed, unable);
}
示例2: setDrawableColor
import android.graphics.drawable.ColorDrawable; //导入方法依赖的package包/类
static void setDrawableColor(Drawable drawable, int color) {
drawable.mutate();
if (drawable instanceof ShapeDrawable) {
ShapeDrawable shapeDrawable = (ShapeDrawable) drawable;
shapeDrawable.getPaint().setColor(color);
} else if (drawable instanceof GradientDrawable) {
GradientDrawable gradientDrawable = (GradientDrawable) drawable;
gradientDrawable.setColor(color);
} else if (drawable instanceof ColorDrawable) {
ColorDrawable colorDrawable = (ColorDrawable) drawable;
colorDrawable.setColor(color);
}
}
示例3: background
import android.graphics.drawable.ColorDrawable; //导入方法依赖的package包/类
@ProtoMethod(description = "Changes the title bar color", example = "")
@ProtoMethodParam(params = {"r", "g", "b", "alpha"})
public PToolbar background(int r, int g, int b, int alpha) {
int c = Color.argb(alpha, r, g, b);
ColorDrawable d = new ColorDrawable();
d.setColor(c);
mToolbar.setBackgroundDrawable(d);
return this;
}
示例4: setToolbarBackgroundColor
import android.graphics.drawable.ColorDrawable; //导入方法依赖的package包/类
public void setToolbarBackgroundColor(int colorRes) {
if (mToolbar != null) {
ColorDrawable background = (ColorDrawable) mToolbar.getBackground();
background.setColor(getResources().getColor(colorRes));
}
}
示例5: setEditMode
import android.graphics.drawable.ColorDrawable; //导入方法依赖的package包/类
/**
* Updates the ActionBar background color depending on whether we are in edit mode or not.
*
* @param editMode
* <code>true</code> to show edit mode, <code>false</code> otherwise
* @param change
* if <code>true</code> the background will change with animation, otherwise immediately
*/
@SuppressLint("NewApi")
private void setEditMode(final boolean editMode, final boolean change) {
mEditMode = editMode;
mConfigurationListener.setEditMode(editMode);
if (!change) {
final ColorDrawable color = new ColorDrawable();
int darkColor = 0;
if (editMode) {
color.setColor(getResources().getColor(R.color.orange));
darkColor = getResources().getColor(R.color.dark_orange);
} else {
color.setColor(getResources().getColor(R.color.actionBarColor));
darkColor = getResources().getColor(R.color.actionBarColorDark);
}
getSupportActionBar().setBackgroundDrawable(color);
// Since Lollipop the status bar color may also be changed
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow().setStatusBarColor(darkColor);
} else {
final TransitionDrawable transition = (TransitionDrawable) getResources().getDrawable(
editMode ? R.drawable.start_edit_mode : R.drawable.stop_edit_mode);
transition.setCrossFadeEnabled(true);
getSupportActionBar().setBackgroundDrawable(transition);
transition.startTransition(200);
// Since Lollipop the status bar color may also be changed
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
final int colorFrom = getResources().getColor(editMode ? R.color.actionBarColorDark : R.color.dark_orange);
final int colorTo = getResources().getColor(!editMode ? R.color.actionBarColorDark : R.color.dark_orange);
final ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
anim.setDuration(200);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(final ValueAnimator animation) {
getWindow().setStatusBarColor((Integer) animation.getAnimatedValue());
}
});
anim.start();
}
if (mSlider != null && editMode) {
mSlider.closePane();
}
}
}