Questions tagged [drawable]

A Drawable is a graphics-related term which generally means "something to be drawn."

While there are multiple definitions of Drawable in the wild, in most cases a Drawable is a general abstraction for "something that can be drawn." GDK provides a different definition: a Drawable is an element onto which things can be drawn.

2977 questions
556
votes
22 answers

Can the Android drawable directory contain subdirectories?

In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my project. I am wondering if it is explicitly not okay to create a sub…
Pepper Lebeck-Jobe
  • 5,870
  • 2
  • 19
  • 13
349
votes
14 answers

How set background drawable programmatically in Android

To set Background: RelativeLayout layout = (RelativeLayout) findViewById(R.id.background); layout.setBackgroundResource(R.drawable.ready); Is the best way to do it?
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
317
votes
9 answers

How to create Drawable from resource

I have an image res/drawable/test.png (R.drawable.test). I want to pass this image to a function which accepts Drawable, e.g. mButton.setCompoundDrawables(). So how can I convert an image resource to a Drawable?
User7723337
  • 11,857
  • 27
  • 101
  • 182
260
votes
12 answers

setBackground vs setBackgroundDrawable (Android)

I want to set background drawable of a view. There are two methods for this (as far as I see): setBackground and setBackgroundDrawable. When I use setBackground, it says it has been added in API level 16 but my project's min SDK version is 7. I…
Pijusn
  • 11,025
  • 7
  • 57
  • 76
227
votes
11 answers

Android splash screen image sizes to fit all devices

I have a full screen PNG I want to display on splash. Only one error there, and I have no idea what size to put in every drawable folder (ldpi, mdpi, hdpi, and xhdpi). My application is supposed to run good and beautiful on all phones and tablets.…
rel-s
  • 6,108
  • 11
  • 38
  • 50
190
votes
10 answers

Android - drawable with rounded corners at the top only

I had this drawable to have a rounded rectangle as a background:
Aleks G
  • 56,435
  • 29
  • 168
  • 265
180
votes
6 answers

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

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…
Blaskovicz
  • 6,122
  • 7
  • 41
  • 50
135
votes
3 answers

How do I set the rounded corner radius of a color drawable using xml?

On the android website, there is a section about color drawables. Defining these drawables in xml looks like this: #f00 #0000ff
Jay Askren
  • 10,282
  • 14
  • 53
  • 75
123
votes
11 answers

Understanding the Use of ColorMatrix and ColorMatrixColorFilter to Modify a Drawable's Hue

I'm working on a UI for an app, and I'm attempting to use grayscale icons, and allow the user to change the theme to a color of their choosing. To do this, I'm trying to just apply a ColorFilter of some sort to overlay a color on top of the…
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274
116
votes
2 answers

Replace selector images programmatically

I have an ImageView that has a drawable image resource set to a selector. How do I programmatically access the selector and change the images of the highlighted and non-highlighted state? Here is a code of selector:
dropsOfJupiter
  • 6,763
  • 12
  • 47
  • 59
113
votes
14 answers

Android: failed to convert @drawable/picture into a drawable

In my drawable folder I have a few images and they all reference perfect, but when I try and add any more images with the exact same size in the same folder, and try to reference it, is flags up an error "Failed to convert @drawable/picture into a…
Jack Trowbridge
  • 3,175
  • 9
  • 32
  • 56
113
votes
4 answers

Is it possible to rotate a drawable in the xml description?

I am creating an app, with resources that can be reused (because buttons are always the same, but mirrored or rotated). I do want to use the same resource so I don't have to add 3 more resources that are exactly like the original but rotated. But I…
Goofyahead
  • 5,874
  • 6
  • 29
  • 33
112
votes
10 answers

Why isn't my vector drawable scaling as expected?

I am attempting to use vector drawables in my Android app. From http://developer.android.com/training/material/drawables.html (emphasis mine): In Android 5.0 (API Level 21) and above, you can define vector drawables, which scale without losing…
Chris Knight
  • 24,333
  • 24
  • 88
  • 134
101
votes
9 answers

How to programmatically set drawableRight on Android Edittext?

I know about set drawableRight in XML. but i required to do it programmatically because it is change as per some condition.
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
100
votes
7 answers

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

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…
talkol
  • 12,564
  • 11
  • 54
  • 64
1
2 3
99 100