drawable

Android: Cloning a drawable in order to make a StateListDrawable with filters

别说谁变了你拦得住时间么 提交于 2019-12-17 07:04:21
问题 I'm trying to make a general framework function that makes any Drawable become highlighted when pressed/focused/selected/etc . My function takes a Drawable and returns a StateListDrawable, where the default state is the Drawable itself, and the state for android.R.attr.state_pressed is the same drawable, just with a filter applied using setColorFilter . My problem is that I can't clone the drawable and make a separate instance of it with the filter applied. Here is what I'm trying to achieve:

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

戏子无情 提交于 2019-12-17 07:02:54
问题 You can understand why I'm trying to find the dominant color in an image if you use Windows 7. When your mouse over a program in the taskbar, the background of that particular program changes based on the most dominant color in the icon. I have noticed this technique used in other programs as well, but can't remember them off the top of my head. I can see this being helpful in a number of UI techniques that I'm using to develop an application, and I was wondering how finding the most common

@Android display /res/viewable in WebView

别说谁变了你拦得住时间么 提交于 2019-12-17 06:41:34
问题 I am throwing HTML to a webview to render. In the HTML I need to load an image that I have in /res/drawable . I have /res/drawable/my_image.png and code such as this: final WebView browser = (WebView) findViewById(R.id.my_webview); String html = new MyHelper(myObject).getHtml(); browser.loadDataWithBaseURL("", html, "text/html", "UTF-8", ""); Where the String html has something like: <html><head> <h1>Here is the image</h1> <img src="my_image.png" /> </head><html> The question is, what should

How can I write a Drawable resource to a File?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 05:07:10
问题 I need to export some Drawable resources to a file. For example, I have a function that returns to me a Drawable object. I want to write it out to a file in /sdcard/drawable/newfile.png . How can i do it? 回答1: Although the best answer here have a nice approach. It's link only. Here's how you can do the steps: Convert Drawable to Bitmap You can do that in at least two different ways, depending on where you're getting the Drawable from. Drawable is on res/drawable folders. Say you want to use a

Save image to sdcard from drawable resource on Android

[亡魂溺海] 提交于 2019-12-17 03:39:20
问题 I'm wondering how to save an image to user's sdcard through a button click. Could some one show me how to do it. The Image is in .png format and it is stored in the drawable directory. I want to program a button to save that image to the user's sdcard. 回答1: The process of saving a file (which is image in your case) is described here: save-file-to-sd-card Saving image to sdcard from drawble resource: Say you have an image namely ic_launcher in your drawable. Then get a bitmap object from this

how to access the drawable resources by name in android

☆樱花仙子☆ 提交于 2019-12-17 03:05:41
问题 In my application, I need to get the some bitmap drawables somewhere where I do not want to keep the reference R . So I create a class DrawableManager to manage the drawables. public class DrawableManager { private static Context context = null; public static void init(Context c) { context = c; } public static Drawable getDrawable(String name) { return R.drawable.? } } Then I want to get the drawable by name somewhere like this( the car.png is put inside the res/drawables): Drawable d=

how to access the drawable resources by name in android

我的梦境 提交于 2019-12-17 03:03:07
问题 In my application, I need to get the some bitmap drawables somewhere where I do not want to keep the reference R . So I create a class DrawableManager to manage the drawables. public class DrawableManager { private static Context context = null; public static void init(Context c) { context = c; } public static Drawable getDrawable(String name) { return R.drawable.? } } Then I want to get the drawable by name somewhere like this( the car.png is put inside the res/drawables): Drawable d=

Android HTML ImageGetter as AsyncTask

て烟熏妆下的殇ゞ 提交于 2019-12-17 01:43:08
问题 Okay, I'm losing my mind over this one. I have a method in my program which parses HTML. I want to include the inline images, and I am under the impression that using the Html.fromHtml(string, Html.ImageGetter, Html.TagHandler) will allow this to happen. Since Html.ImageGetter doesn't have an implementation, it's up to me to write one. However, since parsing URLs into Drawables requires network access, I can't do this on the main thread, so it must be an AsyncTask. I think. However, when you

How to add shadow using a drawable behind solid color shape in xml?

若如初见. 提交于 2019-12-14 03:16:21
问题 I have a .png image which is a circular shape and is just a shadow. What I have is an ImageButton which has an image for it's android:src property. For it's background I can have an xml file in drawable file. What I want now is to have the shadow image which is a png to go behind another solid shape -> android:shape="oval". <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/shadowimg" /> <item>

Create GLX context in specific region of a window

帅比萌擦擦* 提交于 2019-12-14 02:31:22
问题 I would like to create an OpenGL context with GLX inside a window. However, I do not want it to span over the whole window region. Instead, it should only cover a subregion. For example, GLUT provides a function for this behaviour. Also major toolkits like GTK+ or QT provide GL widgets, which are only subregions of X windows. However I need to work low-level. glXMakeCurrent() accepts a X Drawable identifier. Is it possible to define a Drawable as being a subregion of a window? Or are there