xml-drawable

Android: How to Make A Drawable Selector

▼魔方 西西 提交于 2019-11-27 09:01:22
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 way to go about doing this is to create xml resource in the drawable folder that contains a selector and values. However when I go to make a new android xml resource, there's no option for drawables. What am I missing? As far as I know, the Android XML editor doesn't allow you to create XML drawables. You have to go to the source tab (labeled: filename.xml) and paste in the text manually. It should

Using drawable resources

99封情书 提交于 2019-11-27 09:00:06
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 file looks like: <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <bitmap android:src="@drawable/btn_1"/> </item> </layer-list> btn_1 is another xml file in drawable resources When i'm using an image(*.png) instead of xml drawable it's ok. Can I use a drawable resource as src to bitmap? Just in case here is my btn_1.xml file. It doesn't work even if btn_1 file have no items.

how to add shadow effect on drawable in android

耗尽温柔 提交于 2019-11-27 03:48:42
问题 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 shadow effect on this drawable. my code is ----right_bubble_chat_drawable <?xml version="1.0" encoding="utf-8"?> <shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="15dp" /> <solid android:color="@color/chatrightbubbleColor" />

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

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:54:20
问题 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 So which of variants would be better, nine-patch or drawable xml resource? 回答1: My guess is, NinePatch would be slightly faster in most cases. Here's what I found. GradientDrawable (the one used for rects in xml) uses this code to call through to Canvas which in turn uses native call leading to

Color State List not recognized in Shape Drawable

落花浮王杯 提交于 2019-11-27 02:50:27
问题 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> <shape android:gravity="center" android:shape="rectangle"> <solid android:color="@color/color_stateful" /> </shape> </item> <item android:drawable="@drawable/selector_png_drawable" /> </layer-list> And I also define following color state list resource color_stateful.xml : <?xml version="1.0" encoding="utf-8"?> <selector

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

久未见 提交于 2019-11-27 01:40:02
问题 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 example have either the top or the bottom open. Could anyone show me how to do this? 回答1: Try doing this, though I saw it on some other post <?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 shape with bottom stroke

删除回忆录丶 提交于 2019-11-26 23:23:41
I need to create an android shape so that only the bottom has stroke (a dashed line). When I try the following, the stroke bisects the shape right through the center. Does anyone know how to get it right? the stroke needs to be the bottom line/border. I am using the shape as a background to a TextView. Please, never mind why I need it. <?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="#1bd4f6" /> </shape> </item> <item> <shape android:shape="line" > <padding android

Android shape border with gradient

五迷三道 提交于 2019-11-26 19:49:55
问题 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 don't want a filled rectangle, just the stroke. And I want to apply the gradient to the stroke. <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="360" android:centerColor="#e95a22" android

Using drawable resources

只愿长相守 提交于 2019-11-26 11:15:43
问题 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 file looks like: <layer-list xmlns:android=\"http://schemas.android.com/apk/res/android\" > <item> <bitmap android:src=\"@drawable/btn_1\"/> </item> </layer-list> btn_1 is another xml file in drawable resources When i\'m using an image(*.png) instead of xml drawable it\'s ok. Can I use a drawable resource as

Understanding Android&#39;s <layer-list>

拈花ヽ惹草 提交于 2019-11-26 09:24:35
问题 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 nothing is like expected. Here is a screenshot scaled by 500%: (The wrong colors do not matter) As you can see the size is completely wrong and the paddings are missing. I tried to set real values like width/height and right/left/top/buttom to be sure that android get the point what I want. Here