Android get image path from drawable as string

These all are ways: String imageUri = “drawable://” + R.drawable.image; Other ways I tested Uri path = Uri.parse(“android.resource://com.segf4ult.test/” + R.drawable.icon); Uri otherPath = Uri.parse(“android.resource://com.segf4ult.test/drawable/icon”); String path = path.toString(); String path = otherPath .toString();

Align top of image to top of TextView

You can align a compound-Drawable to the top (or bottom) by creating a custom Drawable that wraps your Drawable, and then manipulate the drawing of your custom Drawable by overriding the method onDraw(Canvas). The sample below is the simplest possible example. This aligns the image to the top, but you can also make it align … Read more

Localization and drawables

Each Android resource can have configuration parts in its resource name. For example you might have a plain image on res/drawable and a image for a high DPI screen on res/drawable-hdpi Here hdpi is a Screen pixel density configration. A list of supported Android resource configurtions can be found from here http://developer.android.com/guide/topics/resources/providing-resources.html The order of … Read more

How to put text in a drawable?

Here is a brief example of a TextDrawable which works like a normal drawable but lets you specify text as the only constructor variable: public class TextDrawable extends Drawable { private final String text; private final Paint paint; public TextDrawable(String text) { this.text = text; this.paint = new Paint(); paint.setColor(Color.WHITE); paint.setTextSize(22f); paint.setAntiAlias(true); paint.setFakeBoldText(true); paint.setShadowLayer(6f, 0, … Read more

Drawable folders in res folder?

I am going to take a guess that “the three drawable folders” are drawable-ldpi, drawable-mdpi, and drawable-hdpi. In that case, if you stick with all of those folders, you need to put one image in each, sized to match the indicated screen density. This is discussed in the online documentation as well as this blog … Read more

Android, Drawable.createFromStream(is, srcname): what’s the 2nd parameter meaning?

It’s basically useless: Based on Froyo source, it is used when creating nine-patch images from the resource, but not when creating a regular Bitmap: 852 private static Drawable drawableFromBitmap(Resources res, Bitmap bm, byte[] np, 853 Rect pad, String srcName) { 854 855 if (np != null) { 856 return new NinePatchDrawable(res, bm, np, pad, srcName); … Read more

Android Button Drawable Tint

You can achieve coloring the drawableleft on a button with this method: Step 1: Create a drawable resource file with bitmap as parent element as shown below and name it as ic_action_landscape.xml under the drawable folder <?xml version=”1.0″ encoding=”utf-8″?> <bitmap xmlns:android=”http://schemas.android.com/apk/res/android” android:src=”https://stackoverflow.com/questions/30938620/@android:drawable/ic_btn_speak_now” android:tint=”@color/white” /> Step 2: Create your Button control in your layout as below … Read more