I would like to create the following background with a layer-list:
So basically a circle which has an outer stroke border.
I created the following XML:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#fff"/>
<size
android:width="10dp"
android:height="10dp"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:color="#ff" android:width="2dp"/>
<size
android:width="25dp"
android:height="25dp"/>
</shape>
</item>
</layer-list>
But this shows only one solid oval. Any help is appreciated!
Try This Change Color as per your requirement
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="60dp"
android:height="60dp"
android:top="15dp"
android:right="15dp"
android:bottom="15dp"
android:left="15dp">
<shape
android:shape="oval">
<solid android:color="#ffffff" />
</shape>
</item>
<item>
<shape
android:shape="oval">
<stroke android:width="8dp"
android:color="#ffffff"/>
</shape>
</item>
</layer-list>
Try this .xml File
Tried to edit also you want to Exact
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:topLeftRadius="20dp"
android:topRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
/>
<solid
android:color="#"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="100dp"
android:height="100dp"
/>
<stroke
android:width="3dp"
android:color="#33779C"
/>
android:shape="oval">>
<solid android:color="#FFFFFF" />
<size android:height="25dp"
android:width="25dp"/>
</shape>
The Result shape Like This...
Related
I have a drawable which is a circle with a stroke. How do I add a margin to that stroke?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#android:color/red" />
</shape>
</item>
</layer-list>
This is what I want:
I've tried adding another <item> with a stroke but that doesn't work
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<stroke
android:width="3dp"
android:color="#android:color/blue" />
</item>
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#android:color/red" />
</shape>
</item>
</layer-list>
Also tried adding it in the same <shape/> tag
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
<stroke
android:width="3dp"
android:color="#android:color/blue" />
<stroke
android:width="3dp"
android:color="#android:color/red" />
</shape>
</item>
I've also tried adding dp to the <item> tag
<item
android:left="6dp"
android:top="6dp"
android:bottom="6dp"
android:right="6dp">
but that only creates margin from the viewport to the drawable
Could someone help me please?
Try this :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#color/black" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="oval">
<stroke
android:width="10dp"
android:color="#android:color/red" />
</shape>
</item>
</layer-list>
For the second one :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient
android:endColor="#android:color/transparent"
android:gradientRadius="20"
android:startColor="#android:color/transparent" />
<stroke
android:width="8dp"
android:color="#android:color/red" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="oval">
<gradient
android:endColor="#android:color/black"
android:gradientRadius="20"
android:startColor="#android:color/black" />
<stroke
android:width="8dp"
android:color="#android:color/transparent" />
</shape>
</item>
</layer-list>
I am looking to design an edit box to look as following - as small tip at both ends
Any help would be really appreciated!.
Thanks,
Use below drawable xml in your textview or editText background:-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
>
<shape android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#FF500778" />
<solid android:color="#FFFFFFFF" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#FFFFFFFF" />
<solid android:color="#FFFFFFFF" />
</shape>
</item>
</layer-list>
Create a drawable file like below and set it as background for your edit text
Drawable file:
<?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="2dp"
android:color="#android:color/darker_gray" />
<solid android:color="#android:color/white" />
</shape>
</item>
<item android:bottom="10dp">
<shape android:shape="rectangle">
<stroke
android:width="2dp"
android:color="#android:color/white" />
<solid android:color="#android:color/white" />
</shape>
</item>
</layer-list>
Result:
make a xml file in your drawable folder with this codes
<?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="#de0b0b" />
<solid android:color="#ffffff" />
</shape>
</item>
<item
android:bottom="5dp"
android:top="0dp">
<shape android:shape="rectangle">
<stroke
android:width="10dp"
android:color="#ffffff" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
</layer-list>
for usage, use
android:background="#drawable/name"
to your textView or EditText
I hope this could help you
I'm trying to achieve this effect, but I can't make the white circular stroke inside the circle. In my implementation, the white stroke appears outside the circle
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip" />
<stroke
android:width="5dip"
android:color="#ffffff" />
<solid android:color="#f50000" />
</shape>
</item>
</layer-list>
Expected output:-
I accomplished this using a <layer-list> and an <inset> oval shape:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#f50000"/>
</shape>
</item>
<item>
<inset
android:insetTop="5dp"
android:insetLeft="5dp"
android:insetRight="5dp"
android:insetBottom="5dp">
<shape android:shape="oval">
<stroke
android:color="#fff"
android:width="5dp"/>
</shape>
</inset>
</item>
</layer-list>
You can control the inset amount and the stroke width by changing the values in the second item
here you go. Just modify a little your file to have two items and add a padding on the second.
I hope it helps:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="oval">
<solid android:color="#f50000" />
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:top="2dp"
android:bottom="2dp">
<shape
android:shape="oval">
<stroke
android:width="2dp"
android:color="#ffffff" />
</shape>
</item>
</layer-list>
You need an xml like this (optimized):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="oval">
<solid android:color="#007" />
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:top="2dp"
android:bottom="2dp">
<shape
android:shape="oval">
<stroke
android:width="1dp"
android:color="#f00" />
<size
android:width="25dp"
android:height="25dp" />
</shape>
</item>
</layer-list>
or xml like this (not optimized):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#007" />
<size
android:width="25dp"
android:height="25dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke
android:width="8dp"
android:color="#android:color/transparent" />
<solid android:color="#f00" />
<size
android:width="45dp"
android:height="45dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke
android:width="10dp"
android:color="#android:color/transparent" />
<solid android:color="#007" />
<size
android:width="10dp"
android:height="10dp" />
</shape>
</item>
</layer-list>
for this result:
I am trying to draw a custom shape which I can use as a background for my layout. But I am not able to do so. Is it possible to draw a shape as below using xml in android. I am not getting how to cut the semicircle shape from the vertical centres of rectangle.
Use layer-list to make this custom shape drawable.
/res/drawable/custom_shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Transparent Rectangle -->
<item>
<shape android:shape="rectangle">
<corners
android:topLeftRadius="8dp"
android:topRightRadius="8dp"
android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp" />
<size
android:width="300dp"
android:height="100dp" />
<solid android:color="#FFFFFF" />
</shape>
</item>
<!-- Left Half-Circle -->
<item
android:left="-10dp"
android:right="290dp"
android:top="40dp"
android:bottom="40dp">
<shape android:shape="oval">
<solid android:color="#000000" />
</shape>
</item>
<!-- Right Half-Circle -->
<item
android:left="290dp"
android:right="-10dp"
android:top="40dp"
android:bottom="40dp">
<shape android:shape="oval">
<solid android:color="#000000" />
</shape>
</item>
<!-- Middle Dotted Line -->
<item
android:left="10dp"
android:right="10dp">
<shape android:shape="line">
<stroke
android:width="1dp"
android:dashWidth="10px"
android:dashGap="10px"
android:color="#ff00"/>
</shape>
</item>
</layer-list>
USE:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_shape"/>
OUTPUT:
Hope this will help~
In your case it might be worth to create a resizable bitmap (9-Patch drawable). Follow this guide.
try bellow xml. save it in drawable.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
/>
<solid
android:color="#ffffff"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<stroke
android:width="1dp"
android:color="#000000"
/>
</shape>
It is better to use 9-Patch images. If you can create an image like above you can use https://romannurik.github.io/AndroidAssetStudio/nine-patches.html to create 9-patch image(define expandable area).
Try this xml file in drawable :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle">
<solid android:color="#color/primary" />
<corners android:radius="50dp"/>
</shape>
Please refer the below xml, it may help you out
<?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/black" />
</shape>
</item>
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp">
<shape android:shape="rectangle">
<size
android:width="200dp"
android:height="200dp" />
<solid android:color="#color/colorAccent" />
<corners android:radius="5dp" />
</shape>
</item>
<item>
<shape android:shape="line">
<solid android:color="#android:color/black" />
<stroke android:width="1dp"
android:dashWidth="10px"
android:dashGap="10px"/>
</shape>
</item>
<item
android:bottom="103dp"
android:left="-10dp"
android:right="205dp"
android:top="103dp">
<shape android:shape="oval">
<size
android:width="3dp"
android:height="3dp" />
<solid android:color="#android:color/black" />
<stroke android:width="1dp" />
</shape>
</item>
<item
android:bottom="103dp"
android:left="205dp"
android:right="-10dp"
android:top="103dp">
<shape android:shape="oval">
<size
android:width="3dp"
android:height="3dp" />
<solid android:color="#android:color/black" />
<stroke android:width="1dp" />
</shape>
</item>
</layer-list>
Try below code
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<corners android:radius="3dip" />
<stroke
android:width="1dp"
android:color="#ED2A3C" />
</shape>
I am trying to create a shape drawable like below.
where only the top left section is in different color ( here white ). Thought placing a rectangle with smaller size would let me achieve this but I was wrong. Am I even going in the right direction?
Here's my drawable.xml file.
<?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="15dp" android:height="15dp"/>
<solid android:color="#android:color/white" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#android:color/black" />
</shape>
</item>
</layer-list>
<?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="60dp" android:height="60dp"/>
<solid android:color="#android:color/white" />
</shape>
</item>
<item android:left="40dp">
<shape android:shape="rectangle">
<size android:width="30dp" android:height="30dp"/>
<solid android:color="#ff0000" />
</shape>
</item>
<item android:top="30dp" android:bottom="0dip">
<shape android:shape="rectangle">
<size android:width="10dp" android:height="10dp"/>
<solid android:color="#ff0000" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke android:color="#android:color/black" android:width="1dp"/>
<size android:width="60dp" android:height="60dp"/>
<solid android:color="#ff0000" />
</shape>
</item>
</layer-list>