I've seen it in an iOS app:
and I want to implement a TextView like this in my Android app. So I've made this drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/>
<stroke android:width="1dp"
android:color="#color/colorPrimary" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
but I don't know how to make the blue color on the left.
Anyone could help me?
Thanks
You can try this :
<?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="#FF0000"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item android:left="5dp"
>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
try this
<?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="#FF0000" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
Based on #Er. Joshi answers, I have found this solution that works good:
<?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="#color/blueButton"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp"
android:color="#BDBDBD" />
<padding android:left="10dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
Related
I have been trying to create a vector similar to this image as an android drawable XML but I have been having a few issues.
I am trying to create it as a layer-list so I can have several primitives (a circle and 4 rectangles with rounded corners to act as a semi-circle).
here is my XML code for the drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:right="0dp" android:left="0dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="00dp" android:left="00dp" android:height="40dp" android:width="40dp">
<shape android:shape="oval">
<solid android:color="#000000"/>
</shape>
</item>
</layer-list>
So the problem is I can't get them to spread out as I want them. At the moment they're all on top of each other. When I try to resize one of them, they all adopt that same size for some reason, making impossible to create the semi-circles. Also when I try to move them with android:top and the like, it would drag the others with it so I am kind of lost on how I am supposed to create the shape I'm looking for.
Any help is appreciated.
I had modified your sample , hope this will help you
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:gravity="left|center_vertical" android:right="35dp">
<shape
android:shape="rectangle">
<size android:height="10dp"
android:width="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:topLeftRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
</item>
<item android:gravity="right|center_vertical" android:left="35dp">
<shape
android:shape="rectangle">
<size android:width="10dp"
android:height="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item android:gravity="top|center_horizontal" android:bottom="35dp">
<shape
android:shape="rectangle">
<size android:width="10dp" android:height="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
</item>
<item android:gravity="bottom|center_horizontal" android:top="35dp">
<shape android:shape="rectangle">
<size android:height="10dp"
android:width="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:gravity="center_horizontal|center_vertical">
<shape android:shape="oval">
<size android:height="20dp"
android:width="20dp"/>
<solid android:color="#000000"/>
</shape>
</item>
</layer-list>
I'm trying to implement a view like what's in this link here: https://imgur.com/a/6b75AMp
This is the layer-list I'm using:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesLightGreen"/>
</shape>
</item>
<item android:left="8dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesBackground"/>
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
// The width and color of the border
<stroke
android:width="1dp"
android:color="#3C341F" />
// The desired corner radius. reduce it to keep it less rounded
<corners android:radius="10dp" />
<solid
android:color="#F0ECE0"
/>
</shape>
</item>
</layer-list>
However, the border doesn't show up. If I play around with the order of the items--for example, if I make the vertical stripe the last item--then the border might show up, but the vertical stripe won't. How do I get everything in the layer-list to show up properly?
try the following code you will get a hint
<?xml version="1.0" encoding="utf-8"?>
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesLightGreen" />
</shape>
</item>
<item android:left="4dp" android:top="4dp" android:right="4dp" android:bottom="4dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesBackground" />
</shape>
</item>
<item android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#3C341F" />
<corners android:radius="10dp" />
<solid android:color="#F0ECE0" />
</shape>
</item>
I have modified some of your code, use it and chech the output.
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/colorPrimary"/>
</shape>
</item>
<item android:left="8dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/colorAccent"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<stroke android:color="#000000" android:width="2dp"/>
</shape>
</item>
How can I draw this gradient border(border is fade out to transparent) and radial gradient background?
My code :
Drawable/bg.xml
Radial gradient code is here
Drawable/border.xml
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_blue_light"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:left="3dp" android:right="3dp" android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:height="5dp" android:left="30dp" android:right="30dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="200dp"/>
<gradient android:endColor="#color/transparent"
android:centerColor="#color/white"
android:startColor="#color/transparent"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:endColor="#color/white"
android:startColor="#android:color/transparent"
android:angle="-90" />
</shape>
</item>
I want this result :
<?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="#android:color/holo_blue_light"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:left="3dp" android:right="3dp" android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:width="40dp" android:left="70dp" android:right="200dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary"/>
<gradient android:endColor="#color/white"
android:startColor="#color/transparent"/>
</shape>
</item>
<item android:width="40dp" android:left="240dp" android:right="20dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<gradient android:endColor="#color/transparent"
android:startColor="#color/white"/>
</shape>
</item>
<item android:left="110dp" android:right="120dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:endColor="#color/white"
android:startColor="#color/transparent"
android:angle="-90" />
</shape>
</item>
</layer-list>
Create this rectangle.xml file inside the drawable folder.
Copy this code into it.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#000000"
android:startColor="#FFFFFF" />
<corners android:radius="10dp" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#af25e1" />
<corners android:radius="10dp" />
<size
android:width="250dp"
android:height="150dp" />
</shape>
</item>
</layer-list>
and set it as the background to your container.
You can change it according to your needs
Hope it works for you.
I need to create some drawables that look like image below, is there a way to do this in xml?
Edit:
I have got this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/darker_gray" />
<corners android:radius="6dp" />
</shape>
</item>
<item
android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="#color/dark_gray" />
<corners android:radius="6dp" />
</shape>
</item>
</layer-list>
it's the same like on the picture without that blue corner and I have no idea how to do that diagonal shape. Now I'm using 9 patch, but since all my other buttons are in xml, I was just wondering if there is some way to write this also in xml
Try this code, i guess this is what you want:
draw.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#333333" />
<solid android:color="#333333" />
<padding android:bottom="3dp"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#000000" />
<solid android:color="#000000" />
<padding android:bottom="1dp"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<size android:width="50dp"
android:height="50dp"/>
<stroke android:color="#android:color/transparent" android:width="0dp"/>
<solid
android:color="#android:color/holo_blue_light" />
<corners android:radius="5dp"/>
</shape>
</rotate>
</item>
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#android:color/transparent" />
<solid android:color="#android:color/transparent" />
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
and in your layout file
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerInParent="true"
android:background="#drawable/draw" >
</RelativeLayout>
You should use layer list to combine multiple drawables below is an example.
You should also check this very complete guide to android drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#585858" />
<solid android:color="#FF9009" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item android:left="10dp" android:top="20dp" android:bottom="20dp" android:right="150dp">
<shape
android:shape="oval">
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#118C4E" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item android:left="150dp" android:top="20dp" android:bottom="20dp" android:right="10dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#C1E1A6" />
<padding android:bottom="1dp"/>
</shape>
</item>
</layer-list>
This is what I came up with.
<?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="#color/grey" />
<padding
android:bottom="1dp" />
<corners
android:radius="0dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/white" />
<corners
android:radius="1dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
This is working however the bottom radius is showing up whatever values I place on it.
Actually in only takes the topLeftRadius to make it looks like this
<corners
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp"/>
I had same problem, try it. it worked for me fine. I just add android:top="10dp" to second item. So, it causes to round just top corners.
<?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="#color/dialog_title_bar_blue"/>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item
android:top="10dp">
<shape android:shape="rectangle">
<solid
android:color="#color/dialog_title_bar_blue"/>
</shape>
</item>
</layer-list>
Hi here is your solution "Cheers :) "
first add this layout as background.
Then in the below add a view as aline.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<!-- you can use any color you want I used here gray color -->
<solid android:color="#ffffff" />
<corners
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
</shape>
And the view
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#android:color/black"/>
Issue:
there is a bug as mentioned here
Solution:
the bug has been solved in api12.
so give it a try by providing appropriate resources.create two xml files with same name and put one of them into drawable folder and another into drawable-v12 folder.
-> In drawable folder:
<?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="#color/grey" />
<padding
android:bottom="1dp" />
<corners
android:radius="0dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/white" />
<corners
android:radius="1dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
-> In drawable-v12 folder:
<?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="#color/grey" />
<padding
android:bottom="1dp" />
<corners
android:radius="0dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/white" />
<corners
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
I hope it will be helpful !
<item>
<shape>
<corners
android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="0.1dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="#800000" />
<stroke
android:width="3dp"
android:color="#android:color/black" />
</shape>
</item>
<item android:bottom="3dp">
<shape>
<corners
android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="0.1dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<solid android:color="#800000" />
</shape>
</item>