Questions tagged [xml-drawable]

Solid drawables in android, these drawables are placed in 'drawable' folder inside 'res' folder, these are saved as xml files

xml-drawable
Filter by
Sorted by
Tagged with
73 votes
4 answers
29k views

Using drawable resources

I have this problem, see the trace stack: E/AndroidRuntime(2410): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <bitmap> requires a valid src attribute My xml ...
Alexander Gubarets's user avatar
62 votes
2 answers
96k views

Understanding Android's <layer-list>

I don't understand how the layer-lists work. I read the official documentation with some examples but it does not work for me like expected. I want four squares which should be padded with 1dp, but ...
rekire's user avatar
  • 47.6k
57 votes
5 answers
39k views

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

I looked through multiple similar questions, although I haven't found a proper answer to my issue. I have a drawable, defined in shape.xml <?xml version="1.0" encoding="utf-8"?&...
mol's user avatar
  • 2,647
50 votes
6 answers
78k views

Android shape border with gradient

I want to create a border for a linearLayout. So I decide to create a shape. I want the border to have a gradient. The following is not doing it. It fills the rectangle and then creates a stroke. I ...
learner's user avatar
  • 11.7k
44 votes
10 answers
24k views

How to preview xml drawable?

I'm working on pretty complex xml drawable and i was wondering if there is any tool/plugins which allow me to preview my drawable ? I'm looking for something similar to the "Graphical layout" tab ...
grunk's user avatar
  • 14.8k
42 votes
5 answers
64k views

how to get android gradient center light effect?

i want something like following image i tried it using drawable shape <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:...
Ajeet47's user avatar
  • 1,869
36 votes
2 answers
66k views

Android: How to Make A Drawable Selector

I feel like this is kind of a silly question, but here I go anyways. I have an image button, and I want to be able to change it's image everytime it is clicked. The API seems to say that the best ...
aamiri's user avatar
  • 2,430
36 votes
1 answer
22k views

Android: how to use the current theme's colors in a drawable xml?

I have defined two themes with different primary, primary dark, primary light and accent colors. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="...
user3290180's user avatar
  • 4,340
36 votes
2 answers
32k views

How to use a shape drawable together with an image?

I have this difficulty to have both rounded corner and a background image in my LinearLayout. I know I can achive the rounded corner by using the shape drawable XML, but if I put the shape drawable ...
Surya Wijaya Madjid's user avatar
34 votes
2 answers
16k views

Android dashed line drawable potential ICS bug

The following is a dashed line, defined as a ShapeDrawable in XML: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <size android:...
Chris Horner's user avatar
  • 1,994
33 votes
3 answers
90k views

how to add shadow effect on drawable in android

I have created chat bubble with drawable which looks fine, now I want to add shadow effect below the drawable so it make 3d effect.I don't want to use 9-pitch image. I just want to know how i can add ...
maddy d's user avatar
  • 1,536
31 votes
2 answers
58k views

Android button select and press drawable

I'm trying to make a button with state press and select, I already did the same with tabs and it works but I don't know why here does not work. I have done it like this: button_sel.xml <shape ...
croigsalvador's user avatar
30 votes
4 answers
20k views

Android circular progress bar with rounded corners

I am trying to get a circular progress bar with rounded corner as shown below. But I am not able to get the rounded corner so far I am able to get the circular progress bar. I am trying to draw it ...
Rakesh's user avatar
  • 4,057
30 votes
2 answers
15k views

Change shape border color at runtime

I have this shape in my drawable folder: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <...
Zelter Ady's user avatar
  • 6,308
28 votes
2 answers
43k views

round corners with border color

I am using the following code to get rounded corners as well as a colored outline: <?xml version="1.0" encoding="UTF-8"?> <gradient android:startColor="@color/white" android:...
Ankush's user avatar
  • 6,877
23 votes
1 answer
23k views

How do I make a drawable from multiple images?

I have three 9-patch PNG's which together make up the background for a button (left side, middle, right side). I would like to combine these three images together in a drawable which I can specify as ...
howettl's user avatar
  • 12.5k
19 votes
4 answers
17k views

Android TextView DrawableTint on pre v23 devices

Is there any way we can tint the Drawable used in the TextView? DrawableTint works only on API level 23 and above. Currently I'm using a Vertical Linear Layout to achieve my requirement. <...
Nishanth Sreedhara's user avatar
19 votes
3 answers
18k views

Android tool to generate selector xml for buttons

I was wondering if anyone knows of a tool to generate xml selector files for your custom buttons. I'm getting a bit tired creating buttons, convert them to .9.png files and then copying and pasting a ...
Entreco's user avatar
  • 12.8k
17 votes
4 answers
39k views

set shape background to transparent in android

I have a shape drawable that I want to use as a background. I want the shape to be transparent. But so far it's not. How do I do that? Here is what I have: <?xml version="1.0" encoding="utf-8"?>...
Cote Mounyo's user avatar
  • 13.9k
16 votes
3 answers
25k views

Create borders on a android view in drawable xml, on 3 sides?

I want to make a drawable for my Android button, defined as drawable. I found I could set all the borders by using a rectangle, but I got kinda stuck when I wanted it on three sides. I want for ...
user717572's user avatar
  • 3,636
14 votes
1 answer
12k views

Glossy gradient with android drawable xml

I'm trying to bring out a glossy xml drawable gradient as a background to a layout. I am already using the start color and end color boring linear gradient. <item> <shape> &...
Wesley's user avatar
  • 1,808
14 votes
5 answers
6k views

How to make round corners for a ring shape in Android drawable

I have a custom progress bar that looks like this: Here's the .xml code I've used to create it: background_drawable.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://...
Yenn's user avatar
  • 200
13 votes
4 answers
11k views

How to create android drawable consisting of two colors side by side?

Uisng XML is it possible to create a drawable where half of it would be color1 and another half would be color2? When I set that drawable as a background of a view it should look like in the image ...
Egis's user avatar
  • 4,871
13 votes
3 answers
7k views

Color State List not recognized in Shape Drawable

I define following drawable my_background_drawable.xml: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> ...
a.ch.'s user avatar
  • 8,331
12 votes
4 answers
16k views

How to save, export, or convert an Android XML Drawable as a PNG image file?

I have a gradient I really like but I created it using XML drawable: <gradient android:startColor="#DD181C18" android:endColor="#809C7D5A" android:angle="90"/> What would be an ...
TryTryAgain's user avatar
  • 7,762
11 votes
1 answer
4k views

What should i use for better performance, nine-patch or drawable xml resource?

What is the best way to set background for some view? For example 2 variants of backround: background with gradient, rounded corners and border background with just one color and rounded corners ...
cooperok's user avatar
  • 4,257
11 votes
1 answer
15k views

Error inflating class <unknown>

I am trying to work my way in UI. I am trying to set stateListDrawable for list entries. All I am trying to do is change the color of the list item's layout when the item is pressed, and while the ...
Mohit's user avatar
  • 331
11 votes
5 answers
5k views

Reuse drawable images for different screen sizes and densities on Android

Context: I'm developing an Android application for tablets (landscape) with image resources which has a resolution of 1920x1200. That resolution fits on the following screen sizes and densities: ...
jbc25's user avatar
  • 1,192
11 votes
3 answers
6k views

Possible to create a fixed-width drawable in XML?

I'm trying to simplify some graphics from requiring a 9-patch for each density, to just using an XML drawable. It's a fairly simple graphic: 2 Segments: 8dp wide for both segments Top segment is 2dp ...
Kevin Coppock's user avatar
11 votes
1 answer
3k views

Vertical-striped background in XML?

I want to set a View background that is a regular grid of vertical stripes. The stripes alternate between two colors. (For example, across a single row, there might be 6 pixels of light gray followed ...
Ted Hopp's user avatar
  • 234k
10 votes
1 answer
26k views

How to make bottom border in drawable shape XML selector?

I'm trying to create a drawable shape with different states for my button. So I wrote this: <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed=...
Igal's user avatar
  • 5,933
10 votes
4 answers
10k views

Android - Make check icon using xml drawable

How can I make this shape using xml drawable? Been fighting over it quite some time and can't get it done.
Anonymous's user avatar
  • 4,730
10 votes
3 answers
23k views

Drawing Circle programmatically using Android ShapeDrawable

I have a requirement in my project to draw a circle in runtime dynamically. So for that purpose I am using ShapeDrawable to create circle programmatically, but unfortunately I could not find any class ...
Chandru's user avatar
  • 5,954
9 votes
1 answer
14k views

Selector, Layer-list and shape/bitmap in the same xml

I have this code in an xml inside the drawable folder: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:...
gian1200's user avatar
  • 3,760
9 votes
2 answers
1k views

Using theme references in XML drawables requires API level 21

Is there a way to make following code compatible with lower API levels: <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="?android:attr/...
Mir-Ismaili's user avatar
  • 15.4k
8 votes
2 answers
3k views

XML drawable having different behavior on 4.3 and 4.1.2

I have the folowing drawable, <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:...
Simo's user avatar
  • 1,220
8 votes
2 answers
4k views

app:srcCompat - Vector drawable shows up in design preview, but doesn't show up in app

drawable/information.xml <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" ...
q126y's user avatar
  • 1,639
8 votes
1 answer
2k views

Scale Drawable - does setImageLevel dictate the scale?

I have created a small test app to try out scale drawable. I define my drawable in xml and save it as scale_up.xml. I have a main.xml layout file with an ImageView. I use android:src="@drawable/...
idig's user avatar
  • 331
7 votes
3 answers
29k views

how to change the image of a button with every click?

I created a button in the layout . In the Drawable folder I created a XML file named btn01_state. The btn01_state.xml is assigned to the button i created through "android:background=@drawable/...
Androelpha's user avatar
7 votes
2 answers
9k views

line drawable below textview not showing

I have a textview i want to show a line below it. I am using the drawableBottom attribute to do this. Here is my code <TextView android:id="@+id/total" android:layout_width="fill_parent" ...
arjukhan's user avatar
  • 177
7 votes
1 answer
2k views

Ripple Effect with custom drawable xml?

I need to add ripple effect for all controls to add the liveliness to the Application. Since my minimum api level 18, so i can't able to use <ripple> in drawable xml. Also all my controls have ...
Keerthivasan's user avatar
  • 1,661
6 votes
1 answer
5k views

Rectangle inside another rectangle

Is it possible to create drawable from xml like on the picture? The first rectangle contains a second rectangle. If yes, please explain to me how.
Zheka's user avatar
  • 287
6 votes
3 answers
7k views

How to create curved bottom border rectangle in android?

how to create android drawable with perfect curved bottom using xml like this : i have tried this xml, but the result didn't perfect <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:...
andri_sasuke's user avatar
6 votes
3 answers
7k views

How to prevent android layer drawable shapes (e.g. circle) from scaling

I try to create a simple illustration using XML layer-list drawable. I have two shapes, a circle and a rectangle I want a circle not to scale. The following is the layout: <LinearLayout xmlns:...
Michael Kariv's user avatar
6 votes
0 answers
285 views

Theme attributes in pre-lollipop Drawable using DrawableCompat?

I've successfully used theme attributes (ex. ?attr/colorPrimary) within a VectorDrawable loaded through VectorDrawableCompat. Is there a way to do the same with a simple Drawable containing a shape ...
djdmbrwsk's user avatar
  • 602
5 votes
1 answer
3k views

Android Google Maps Marker: Released unknown imageData reference

I'm trying to add support to tablets in my app and run into IllegalArgumentException thrown by this line of code: marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.arrow_green_10by19)) ...
Walter Roncada's user avatar
5 votes
2 answers
4k views

How to make a rounded dashes or dots for line drawable shape

Is there a way that can I make the cap/dot rounded, like in the attached picture? <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke ...
Alaa AbuZarifa's user avatar
5 votes
3 answers
3k views

"Nothing to show" when I tried to insert a new Vector Asset in Android Studio

"Nothing to show" error - vector asset Hey, all. So, recently I updated my Android Studio Version to 4.1 (the latest version). I wanted to add a vector asset just like the usual but..somehow....
Tinara Nathania's user avatar
5 votes
2 answers
13k views

Android XML drawable rounded corners with bitmap tag

I have next XML drawable blue_button <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <layer-list> ...
Dmitry Nelepov's user avatar
5 votes
1 answer
5k views

set image source to Bitmap in Drawable

I have created XML file in drawable folder as code below: XML Name is : background_bitmap_layout.xml <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/...
DearDhruv's user avatar
  • 798

1
2 3 4 5 6