Java Code Examples for android.graphics.drawable.ColorDrawable.setColor()

The following are Jave code examples for showing how to use setColor() of the android.graphics.drawable.ColorDrawable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OneDrawable   File: OneDrawable.java   Source Code and License Vote up 5 votes
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);
}
 
Example 2
Project: slideview   File: Util.java   Source Code and License Vote up 5 votes
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);
    }

}
 
Example 3
Project: phonk   File: PToolbar.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 4
Project: phonk   File: PToolbar.java   Source Code and License Vote up 5 votes
@ProtoMethod(description = "Changes the title bar color", example = "")
@ProtoMethodParam(params = {"r", "g", "b", "alpha"})
public PToolbar background(int r, int g, int b) {
    int c = Color.rgb(r, g, b);

    ColorDrawable d = new ColorDrawable();
    d.setColor(c);
    mToolbar.setBackgroundDrawable(d);

    return this;
}
 
Example 5
Project: AndroidMuseumBleManager   File: ToolbarActivity.java   Source Code and License Vote up 4 votes
public void setToolbarBackgroundColor(int colorRes) {
    if (mToolbar != null) {
        ColorDrawable background = (ColorDrawable) mToolbar.getBackground();
        background.setColor(getResources().getColor(colorRes));
    }
}
 
Example 6
Project: Android-DFU-App   File: UARTActivity.java   Source Code and License Vote up 4 votes
/**
 * 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();
		}
	}
}