android-drawable

Retrieve drawable resource from Uri

给你一囗甜甜゛ 提交于 2019-11-28 08:20:21
I'm storing the drawable resource path in an Uri in this way: Uri uri = Uri.parse("android.resource://my_app_package/drawable/drawable_name"); How do I get the Drawable that the uri is referencing? I don't want to put it in an ImageView, just retrieve the Drawable (or Bitmap) object. pskink getContentResolver cr object then call: is = cr.openInputStream(uri) and finally call: Drawable.createFromStream(InputStream is, String srcName) ...Here's an actual working code example so you can see for yourself: try { InputStream inputStream = getContentResolver().openInputStream(yourUri); yourDrawable =

How can I convert String to Drawable

时光怂恿深爱的人放手 提交于 2019-11-28 07:48:52
I have many icon in drawable folder and I have their name as String. How can I access to drawable folder and change background imageView (or any view) use these name in dynamically. Thanks This can be done using reflection: String name = "your_drawable"; final Field field = R.drawable.getField(name); int id = field.getInt(null); Drawable drawable = getResources().getDrawable(id); Or using Resources.getIdentifier() : String name = "your_drawable"; int id = getResources().getIdentifier(name, "drawable", getPackageName()); Drawable drawable = getResources().getDrawable(id); Then use this for

Android Studio drawable folders

瘦欲@ 提交于 2019-11-28 07:07:18
In Android Studio, I can't figure out where to put images to be used inside the app. The drawable folder isn't broken down into drawable-hdpi, drawable-ldpi, etc. I saw another question asking this and the answer was to switch to Project view instead of Android view but drawable is only one folder there too. There is mipmap-hdpi, mipmap-ldpi, etc, but people are saying that's only for app icons. I'm confused. If you don't see a drawable folder for the DPI that you need, you can create it yourself. There's nothing magical about it; it's just a folder which needs to have the correct name.

Building a 9 patch drawable at runtime

白昼怎懂夜的黑 提交于 2019-11-28 06:59:18
I am successfully building a 9patch drawable at runtime on Android 3.0+ using the excellent gist provided by Brian Griffey (found here ). Essentially I load the raw (no patches) graphic file from the network and the filename contains the cap insets that I need to use in order to scale the image accordingly. I then use these values with the class found above and apply the image as a background to a variety of elements (such as TextView , ImageButton , Button , ViewGroup , etc). This works perfectly as you can see here: However, running the same code on Android 2.3.x yields the result: I've

Progress bar with rounded corners?

冷暖自知 提交于 2019-11-28 04:39:19
I am trying to achieve this progress bar design: The current code that I have produces this: This is the code: <item android:id="@android:id/background"> <shape> <corners android:radius="8dp"/> <solid android:color="@color/dirtyWhite"/> </shape> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="8dp"/> <solid android:color="@color/colorPrimaryDark"/> </shape> </clip> </item> My progress bar: <ProgressBar android:id="@+id/activeProgress" style="?android:attr/progressBarStyleHorizontal" android:layout_width="300dp" android:layout_height="wrap_content"

Add gradient to imageview

守給你的承諾、 提交于 2019-11-28 04:20:41
I want to add a gradient on the bottom of my image . Something like this : I tried something like this but I only get the gradient no image.. <ImageView android:id="@+id/trendingImageView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/trend_donald_sterling" android:src="@drawable/trending_gradient_shape" /> trending_gradient_shape: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="90" android:endColor="@android:color/darker_gray" android:startColor="@android:color/darker

Android: Alternative for context.getDrawable()

淺唱寂寞╮ 提交于 2019-11-28 04:02:52
I have used context.getDrawable() like this in my project: Drawable greenProgressbar = context.getDrawable(R.drawable.custom_progressbargreen); But Eclipse is giving me an error that it needs a Minimum API level of 21 . This would mean after a quick google search my APP will only be usable on Android 5.0 . Since not all devices are using this version of android I would like to have an alternative for context.getDrawable() . user2417480 The previously accepted method has been deprecated, according to the SDK 22 documentation: Prior to android.os.Build.VERSION_CODES#JELLY_BEAN, this function

How can I recreate this background in xml?

寵の児 提交于 2019-11-27 23:10:52
I've been trying to recreate a background image in xml (as drawable). Since the background is a simple shape, it would be better if it is created as xml drawable. The is a really large gradient circle that squares off at the left, top and right border. What I've tried <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <size android:height="20dp" /> <gradient android:type="linear" android:startColor="@color/gradientLeft" android:centerColor="@color/gradientMiddle" android:endColor="@color

BitmapFactory.decodeResource() returns null for shape defined in xml drawable

喜你入骨 提交于 2019-11-27 21:09:34
问题 I looked through multiple similar questions, although I haven't found proper answer on my query. I have a drawable, defined in shape.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="@color/bg_color" /> </shape> I want to convert it to Bitmap object in order to perform some operations, but BitmapFactory.decodeResource() returns null. This is how I'm doing it: Bitmap bmp = BitmapFactory

Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi

假装没事ソ 提交于 2019-11-27 20:44:56
I have a rough idea of what each of these directories are for, but I'm not really clear on the concept and I have some specific questions. For example, what are the target DPIs for each directory? When you create an asset, should it be at that target DPI or should it be at the more normal 72dpi screen DPI? If you're targeting multiple devices, is it ever appropriate to put a PNG in drawable or should you always have multiple versions slightly tailored to the specific screens? Thanks. As the others have suggested, the Android online documentation has great articles on this. However, I'm going