Create a new color drawable

android:color drawable xml
change drawable color android programmatically
android:drawable
android change textview drawable color programmatically
solid color drawable
drawable icon color
android add color filter to drawable
set imageview drawable color

I am trying to convert a hex value to an int so I can create a new color drawable. I'm not sure if this is possible, but according to the documentation, it should. It plainly asks for

public ColorDrawable (int color)

Added in API level 1 Creates a new ColorDrawable with the specified color.

Parameters color The color to draw.

So, my code isn't working because I'm getting an Invalid int: "FF6666" error. Any ideas?

int decode = Integer.decode("FF6666");
ColorDrawable colorDrawable = new ColorDrawable(decode);

Since you're talking about hex you have to start with 0x and don't forget the opacity.

So basically: 0xFFFF6666

ColorDrawable cd = new ColorDrawable(0xFFFF6666);

You can also create a new colors.xml file into /res and define the colors like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="mycolor">#FF6666</color>
</resources>

and simply get the color defined in R.color.mycolor

getResources().getColor(R.color.mycolor)

How to create a Drawable with needed background color , You should try using a ColorDrawable. It can be Color.GREEN // Set the correct new color d.setColorFilter( iconColor, Mode.MULTIPLY );  Creates a new ColorDrawable with the specified color. Color Drawable (Int Ptr, Jni Handle Ownership) Color Drawable (Int Ptr, Jni Handle Ownership) A constructor used when creating managed representations of JNI objects; called by the runtime.


For using with ContextCompat and rehuse the color you can do something like this:

ColorDrawable colorDrawable = new ColorDrawable(ContextCompat.getColor(this, R.color.white));

ColorDrawable, Creates a new ColorDrawable with the specified color. Public methods. open Unit. applyTheme(t  Emphasizing what I think the previous commenter is saying, this solution changes the colors if the 2 parameters in the LightingColorFilter are different, e.g., ColorFilter filter = new LightingColorFilter(Color.BLACK, Color.LTGRAY); will change black to gray in the drawable. – hBrent Aug 25 '14 at 16:32


It should be like this...

ColorDrawable cd = new ColorDrawable(0xffff6666);

Note I used 8 hex digits, not 6 hex digit . which add to transparency

android.graphics.drawable.ColorDrawable.setColor java code , public void setValue(@NonNull ColorDrawable object, int value) { object.​setColor(value); new ColorDrawable(color); new ColorDrawable(); String str;​new ColorDrawable(Color.parseColor(str)) clearColorFilter(); } if (Build.​VERSION. Stack Overflow Public this is class i want to set the background color of btn and then i want use my drawable. You can create a new drawable and assign the


I think you have to use :

public static int parseColor (String colorString)

Added in API level 1 Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception. Supported formats are: #RRGGBB #AARRGGBB red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray, darkgray, grey, lightgrey, darkgrey, aqua, fuschia, lime, maroon, navy, olive, purple, silver, teal

android.graphics.drawable.ColorDrawable java code examples , setBackgroundDrawable(new ColorDrawable(Color.BLACK)); buildActivity(​Activity.class).create(); mActivity = mActivityController.get(); mMountContent = new  How To Create Drawable Resource XML File in Android Studio: Step 1: Firstly, Right Click on drawable as shown in figure below. Step 2: After that Go New > Drawable resource file as shown in figure below. Step 3: After that New Resource file dialog box open on your computer screen. Enter File name in the text box and then press OK.


By followingthe above advice,to be a summary of this question:

  1. ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#ce9b2c"));`

  2. ColorDrawable colorDrawable = new ColorDrawable(0xFFCE9B2C); Note there is 8 hex digits, not 6 hex digit,which no work. Case all

  3. ColorDrawable colorDrawable = new ColorDrawable(ContextCompat.getColor(mContext,R.color.default_color));

Selecting up to you!

Java Code Examples android.graphics.drawable.ColorDrawable, setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //​AndroidRuntimeException: requestFeature() must be called before adding content  then the drawable will return only null value with the following code Drawable drawable = (Drawable) ivshowing.getDrawable(); So, it's better to set the image with the following code, if you wanna retrieve the drawable from a particular view. ivshowing.setImageResource(R.drawable.one); only then the drawable will we converted exactly.


ColorDrawable Class (Android.Graphics.Drawables), A specialized Drawable that fills the Canvas with a specified color. Creates a new ColorDrawable with the specified color. ColorDrawable(IntPtr  Every Drawable is stored as individual files in one of the res/drawable folders. Typically you would store bitmaps for different resolutions in the -mdpi, -hdpi, -xhdpi, -xxhdpi subfolders of res/drawable. The ADT project creation wizard creates these folders by default.


ColorDrawable, Public Constructors. ColorDrawable(). Creates a new black ColorDrawable. ColorDrawable(int color). Creates a new ColorDrawable with the specified color. A unique resource ID for this drawable. To create a new resource ID for this item, use the form: "@+id/name". The plus symbol indicates that this should be created as a new ID. You can use this identifier to retrieve and modify the drawable with View.findViewById() or Activity.findViewById(). android:top Integer. The top offset in pixels


Public Constructors. ColorDrawable(). Creates a new black ColorDrawable. ColorDrawable(int color). Creates a new ColorDrawable with the specified color. The idea is that ImageView gets color filter when user touches it, and color filter is removed when user stops touching it. Only 1 drawable/bitmap is in memory, so no need to waste it. It works as it should. class PressedEffectStateListDrawable extends StateListDrawable { private int selectionColor; public PressedEffectStateListDrawable(Drawable drawable, int selectionColor) { super(); this.selectionColor = selectionColor; addState(new int[] { android.R.attr.state_pressed }, drawable);