drawable

How do you obtain a Drawable object from a resource id in android package?

蓝咒 提交于 2019-11-27 19:53:19
问题 I need to get a Drawable object to display on an image button. Is there a way to use the code below (or something like it) to get an object from the android.R.drawable.* package? for example if drawableId was android.R.drawable.ic_delete mContext.getResources().getDrawable(drawableId) 回答1: Drawable d = getResources().getDrawable(android.R.drawable.ic_dialog_email); ImageView image = (ImageView)findViewById(R.id.image); image.setImageDrawable(d); 回答2: As of API 21 , you should use the

Localization and drawables

非 Y 不嫁゛ 提交于 2019-11-27 19:38:00
I want to localize an image by adding the folder res/drawable-hdpi-no, but I get an error stating "invalid resource directory name". What's up with this? As far as I remember, only certain res folders will work. You need to call it drawable-[language code]-r[capitalised localisation code] if I remember rightly. Pretty sure it's one of the Android Tutorials. Yeah here it is http://developer.android.com/resources/tutorials/localization/index.html 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

Android:Draw line on a textview

谁都会走 提交于 2019-11-27 19:33:38
I have asked a question previously titled "Android: Ruled/horizonal lines in TextView" at Android: Ruled/horizonal lines in Textview . But I haven't got required answer. So I'm planing to do this by drawing line on TextView by java.Is there any way to draw Line inside TextView? or if I get end of line from java code then I'll be able to add textview for each line. Any help will be highly appreciated. I'm using the technique of drawing lines between each line of text in EditText and then I will make the EditText non-editable by setting setKeyListener(null) to the custom EditText object so that,

Android get image path from drawable as string

人走茶凉 提交于 2019-11-27 19:20:06
Is there any way that I can get the image path from drawable folder in android as String. I need this because I implement my own viewflow where I'm showing the images by using their path on sd card, but I want to show a default image when there is no image to show. Any ideas how to do that? karan 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 =

Compare names of every resource with the content of a variable of sqlite database

怎甘沉沦 提交于 2019-11-27 18:38:52
问题 I hope you can help me, I already researched my case but didn't found a good answer. I want to compare the content of a variable with the names of all existing resources (if possible only with drawable resources). The question in short: How to compare the String content of an variable with a list of all resource names, preferential only with drawable resources? Or in other words: How to get a list (containing Strings) of all resource names, preferential only drawable resources? The Case: I

Customizing tabs on state in Android

老子叫甜甜 提交于 2019-11-27 18:35:55
I know how to put the icon on each tab, that is no problem. I also ran across this : [Stack Overflow thread on pretty much same thing][1] I followed one of the links from that question and found [this][2] Pretty much, it said to use a selector defined in the XML, sure, did that. But there is no id associated w/ it so I am not sure how to get the selector function as a drawable so I can use it as the icon for the tabs. Maybe I am going about this the wrong way. But this is what I have, and obviously missing something. <selector android:id="@+id/myselector" xmlns:android="http://schemas.android

AnimationDrawable don't work in Android 2.2

走远了吗. 提交于 2019-11-27 18:34:46
问题 I using AnimationDrawable like this: ImageView rocketImage = (ImageView) layout.findViewById(R.id.animation); rocketImage.setBackgroundResource(R.drawable.progress_blue_animation); rocketAnimation = (AnimationDrawable) rocketImage.getBackground(); rocketAnimation.start(); This code work in Android 3.0/4.0/4.1/4.0, but don't work in Android 2.2. How to solve this problem? 回答1: As far as i know, thats a Bug in 2.1, 2.2 A possible workaround could be: ImageView rocketImage = (ImageView) layout

Access resource defined in theme and attrs.xml android

 ̄綄美尐妖づ 提交于 2019-11-27 18:31:16
I have a scenario in which I want to set a Drawable depending upon the theme defined. To explain this further, Here is what I have in code: \res\values\attrs.xml <resources> <declare-styleable name="AppTheme"> <attr name="homeIcon" format="reference" /> </declare-styleable> </resources> res\values\styles.xml <resources> <style name="AppTheme" parent="android:style/Theme"> <item name="attr/homeIcon">@drawable/ic_home</item> </style> </resources> AndroidManifest.xml <application android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label

Loading drawable from sd card

﹥>﹥吖頭↗ 提交于 2019-11-27 18:30:45
问题 I'm trying to load a png image as a drawable from my device sd card. I use the following function but it doesn't work: public Drawable getDrawable() { return new BitmapDrawable(imagePath); } The image path is: mnt/sdcard/MyFolder/image.png The app crashes when I try calling that method, how should I load my png image located in my sdcard and cast it into a Drawable object? 回答1: There is actually a BitmapDrawable constructor straight from file path. The method you are using is depricated. Try:

How to get round shape in Android [duplicate]

对着背影说爱祢 提交于 2019-11-27 18:05:41
This question already has an answer here: How to define a circle shape in an Android xml drawable file? 14 answers How would I achieve a round shape in Android, like below, through an Android shape drawable: 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