Newer versions of Android Studio add only two drawable directories – drawable and drawable-v21

Thank you to everyone who tried to help. You helped me reach the final answer, but no one solution was quite right. @user3137702 was probably the closest, as it IS related to the whole move to vectors/SVGs. I couldn’t find a definitive answer, like something directly from Google (although I imagine it is out there), … Read more

Tiled drawable sometimes stretches

I also got bitten by this problem. Very hard to diagnose, even harder to find similar reports and usable solutions. “Tapas” on the freenode #android-dev irc channel came with the following utility method: public static void fixBackgroundRepeat(View view) { Drawable bg = view.getBackground(); if (bg != null) { if (bg instanceof BitmapDrawable) { BitmapDrawable bmp … Read more

How to get round shape in Android [duplicate]

You need to create a shape drawable in the drawable folder that looks something like: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android” android:shape=”oval” > <gradient android:startColor=”#FFFF0000″ android:endColor=”#80FF00FF” android:angle=”270″/> </shape> (For this example I have saved the drawable as circle.xml and it will have a gradient fill) Then in your layout you need to define a view and … Read more

Android: Change Shape Color in runtime

I’m now creating a Drawable like the one pre-compiler.. as i couldn’t change the color to anything but black, even after trying the hex OR described below. The new code: ShapeDrawable footerBackground = new ShapeDrawable(); // The corners are ordered top-left, top-right, bottom-right, // bottom-left. For each corner, the array contains 2 values, [X_radius, // … Read more

Finding the dominant color of an image in an Android @drawable

In Android 5.0 Lollipop, a class was added to help extract useful colors from a Bitmap. The Palette class, found in android.support.v7.graphics, can extract the following colors: Vibrant Vibrant Dark Vibrant Light Muted Muted Dark Muted Light This Android training page gives all the details you need to use the class (I tried it myself … Read more

Android drawable speech bubble

If you are creating a chat screen you are probably going to want to implement an incoming speech bubble and an outgoing speech bubble. Here is how I did that : shape_bg_incoming_bubble.xml <?xml version=”1.0″ encoding=”utf-8″?> <layer-list xmlns:android=”http://schemas.android.com/apk/res/android”> <item> <rotate android:fromDegrees=”-45″ android:pivotX=”0%” android:pivotY=”0%” android:toDegrees=”0″ > <shape android:shape=”rectangle” > <solid android:color=”@color/primary” /> </shape> </rotate> </item> <item android:left=”16dp”> … Read more