Example usage for android.graphics.drawable ColorDrawable ColorDrawable

List of usage examples for android.graphics.drawable ColorDrawable ColorDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable ColorDrawable ColorDrawable.

Prototype

public ColorDrawable(@ColorInt int color) 

Source Link

Document

Creates a new ColorDrawable with the specified color.

Usage

From source file:Main.java

public static ColorDrawable getCachePlaceHolder() {
    return new ColorDrawable(0xffdcdcdc);
}

From source file:Main.java

public static ColorDrawable getColorDrawableFromColor(int paramInt) {
    return new ColorDrawable(paramInt);
}

From source file:Main.java

public static void setActionBarColor(Activity activity, int color) {
    activity.getActionBar().setBackgroundDrawable(new ColorDrawable(color));
    refreshActionBar(activity);//from   ww w . j  a  v a2  s.co m
}

From source file:Main.java

/**
 * @param color The color/*from w  ww .  ja  v  a 2 s  . c om*/
 * @return A {@link android.graphics.drawable.ColorDrawable}
 */
public static ColorDrawable getColorDrawable(int color) {
    return new ColorDrawable(color);
}

From source file:Main.java

public static ColorDrawable getRandomColor() {
    return new ColorDrawable(Color.parseColor(colors[random.nextInt(8)]));
}

From source file:Main.java

/**
 * helper to create a StateListDrawable for the drawer item background
 *
 * @param selected_color/*from  ww  w  .j  a  v a2  s . co  m*/
 * @return
 */
public static StateListDrawable getDrawerItemBackground(int selected_color) {
    ColorDrawable clrActive = new ColorDrawable(selected_color);
    StateListDrawable states = new StateListDrawable();
    states.addState(new int[] { android.R.attr.state_selected }, clrActive);
    return states;
}

From source file:Main.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public static void setBackground(Activity activity, int background) {

    activity.getActionBar()//from w  w  w .jav  a2s. c om
            .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

    Drawable draw;
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        draw = activity.getResources().getDrawable(background, activity.getTheme());
        activity.getActionBar().setBackgroundDrawable(draw);
    } else {
        draw = activity.getResources().getDrawable(background);
        activity.getActionBar().setBackgroundDrawable(draw);
    }
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable == null)
        drawable = new ColorDrawable(Color.TRANSPARENT);

    Bitmap bitmap;//  ww w. j  a  va2  s  .c  o  m

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null)
            return bitmapDrawable.getBitmap();
    }

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0)
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    else
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}

From source file:Main.java

/**
 * Set action bar background/*from www  .  j a v  a  2 s . co m*/
 *
 * @param activity   The activity to set ActionBar background to.
 * @param resColorId The Drawable color to set the ActionBar to.
 */
public static void setActionBarBackground(Activity activity, int resColorId) {
    // change action bar color
    activity.getActionBar()
            .setBackgroundDrawable(new ColorDrawable(activity.getResources().getInteger(resColorId)));
    activity.getActionBar().setDisplayShowTitleEnabled(false);
    activity.getActionBar().setDisplayShowTitleEnabled(true);
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void setActionBar(Activity activity, int background) {

    // Action Bar Icon
    activity.getActionBar()//  w w  w. j  a  v a  2 s .com
            .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

    // Action Bar Background
    Drawable draw;
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        draw = activity.getResources().getDrawable(background, activity.getTheme());
        activity.getActionBar().setBackgroundDrawable(draw);
    } else {
        draw = activity.getResources().getDrawable(background);
        activity.getActionBar().setBackgroundDrawable(draw);
    }
}