drawable

android drawable from file path

为君一笑 提交于 2019-12-17 21:48:57
问题 I have a file path String of the form "e:\...\xxx.jpg" How do I create a drawable from it? 回答1: You can create a Drawable or Bitmap from a string path like this: String pathName = "/path/to/file/xxx.jpg"; Drawable d = Drawable.createFromPath(pathName); For a Bitmap: String pathName = "/path/to/file/xxx.jpg"; bitmap b = BitmapFactory.decodeFile(pathName); 来源: https://stackoverflow.com/questions/5834221/android-drawable-from-file-path

Android vector compatibility

会有一股神秘感。 提交于 2019-12-17 21:14:54
问题 I'd like to start using vectors for the icons with in the apps I do, but not sure how to deal with the compatibility I'm not interested in any of the third party compat libraries and happy to wait for googles version (Mentioned here VectorDrawable - is it available somehow for pre-Lollipop versions of Android?). So basically for now I'm happy to continue to have the images per resolution as well as an additional for > Lollipop. If the device is higher than 21 it will use the vector otherwise

Add transition to an AnimationDrawable

落爺英雄遲暮 提交于 2019-12-17 20:06:54
问题 I have a set of 10 images, and I want to create an animation where I cross fade between them. I've been looking into built-in Drawable to achieve such a thing, but no luck on that part. There is the AnimationDrawable, that switch between pictures, but it doesn't animate the switch. There is the TransitionDrawable, that cross fade between two pictures, but no more than two. Hell. I looked for some solution on Google, but no luck on that part. So I'm thinking about implementing my own drawable

Retrieving xhdpi app icons from packageManager?

南笙酒味 提交于 2019-12-17 19:53:46
问题 I have an activity in my app wherein a ListView of all installed apps is generated. In addition to the app name, the app icon appears as well. I had created an array of objects containing all the information about the application, among this the icon, and retrieved the icon using: drawableAppIcon = mPackageManager.getApplicationIcon(apps.applicationInfo); Where application is a <PackageInfo> object. The problem with this is that while I readily have access to all the drawables, various apps

Bitmaps on ICS are loaded with wrong pixel format

安稳与你 提交于 2019-12-17 19:34:25
问题 I encountered the following problem. When any bitmap is loaded from resources by an application running on Ice Cream Sandwich, it will likely be rendered incorrectly as if it has been decoded to the format, which differs from the current window format, with no dither applied. However, both, the decoding format and window format have been explicitly set: BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Bitmap.Config.RGBA_8888; and getWindow().setFormat

Android xml layer-list not displayed correctly on some devices

淺唱寂寞╮ 提交于 2019-12-17 19:28:11
问题 I have an xml layer list drawable as a background for view, which is not displayed correctl on some devices. I have a Huawei Ascend Mate with 4.2.2 which displays it ok. On Asus phonepad tablet with 4.1.2 i see just the item shape stroke and dont see the other items. What am I doing wrong? <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > <solid android:color="@color/yellow_color" /> <

Vector Drawable in Layer List on Older Android Versions

风流意气都作罢 提交于 2019-12-17 18:25:52
问题 On newer Android versions, the following code: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="oval"> <solid android:color="#bdbdbd" /> <size android:width="60dp" android:height="60dp" /> </shape> </item> <item android:drawable="@drawable/ic_library_books_black_24dp" android:gravity="center" android:width="40dp" android:height="40dp" > </item> </layer-list> produces this flawlessly: However, earlier

android programmatically blur imageview drawable

北慕城南 提交于 2019-12-17 17:59:06
问题 I want to programmatically blur and unblur images in Android. I hear that android flag "blur" is no longer supported after API 14 , but I wanted to use Java methods anyway. My main problem is manipulating the bitmap from an Imageview drawable. How would I get the bitmap from an imageview and manipulate it (will probably use gaussian blur) and set it back to the imageview? I think the process involves extracting the drawable, converting the drawable to a bitmap, doing my blur method on that

Is it possible to load a drawable from the assets folder?

僤鯓⒐⒋嵵緔 提交于 2019-12-17 17:47:09
问题 Can you load a drawable from a sub directory in the assets (not the drawable folder) folder? 回答1: Hope this help: Drawable d = Drawable.createFromStream(getAssets().open("Cloths/btn_no.png"), null); 回答2: I recommend to use this Drawable.createFromResourceStream(resources,new TypedValue(), resources.getAssets().open(filename), null) which returns properly scaled drawable thanks to resources ... 回答3: Here's a class with static method to get the drawable from the assets. It also closes the

I don't want Android to resize my bitmap Automatically

徘徊边缘 提交于 2019-12-17 16:47:07
问题 I have placed some bitmaps in res/drawable. After I load the bitmaps by BitmapFactory.decodeResource(), I find out that they are resized automatically according the density. This is not what I want. I want them to keep their original size (pixel size). What should I do? 回答1: As was said in another question, using the drawable-nodpi folder will prevent android from resizing your pictures. Additionally, if you want to have multiple versions of an image for hdpi and ldpi format, but don't want