trying to put shadow on button with transparent color.
trying with this selection.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<solid android:color="#00808080" />
<!-- <gradient
android:angle="315"
android:startColor="#1Acccccc"
android:endColor="#00cccccc"
android:type="linear"
/>-->
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<solid android:color="#10808080" />
<!--<gradient
android:angle="315"
android:startColor="#00cccccc"
android:endColor="#1Acccccc"
android:type="linear"
/>-->
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<!--<solid android:color="#20808080"/>-->
<gradient
android:angle="315"
android:endColor="#20808080"
android:startColor="#00cccccc"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<!--<solid android:color="#30808080"/>-->
<gradient
android:angle="315"
android:endColor="#30808080"
android:startColor="#00cccccc"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
<!--<solid android:color="#50808080"/>-->
<gradient
android:angle="315"
android:endColor="#50808080"
android:startColor="#00cccccc"
android:type="linear" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
</shape>
</item>
<item>
<shape>
<padding
android:bottom="1.5dp"
android:left="0dp"
android:right="1.5dp"
android:top="0dp" />
</shape>
</item>
<!-- Background -->
<item>
<shape>
<solid android:color="#80FFFFFF" />
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
i am using this code for shadow its work for me....!
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
As I understood, you need something like 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="#cabababa"/>
<corners android:radius="2dp"/>
</shape>
</item>
<item
android:left="0dp"
android:right="2dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="0dp" />
</shape>
</item>
</layer-list>
Related
I want to make rounded corners for below mentioned layout:
I've created this drawable by using layer-list tags as:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="250dp"
android:height="250dp">
<shape android:shape="rectangle">
<stroke
android:width="15px"
android:color="#android:color/transparent" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item
android:width="#dimen/margin_8"
android:bottom="0dp"
android:top="200dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:width="#dimen/margin_8"
android:bottom="200dp"
android:top="0dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:width="#dimen/margin_8"
android:bottom="0dp"
android:gravity="right"
android:top="200dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:width="#dimen/margin_8"
android:bottom="200dp"
android:gravity="right"
android:top="0dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="#dimen/margin_8"
android:gravity="top"
android:left="0dp"
android:right="200dp"
android:top="-1dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="#dimen/margin_8"
android:gravity="top"
android:left="200dp"
android:right="0dp"
android:top="-1dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="#dimen/margin_8"
android:gravity="bottom"
android:left="0dp"
android:right="200dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="#dimen/margin_8"
android:gravity="bottom"
android:left="200dp"
android:right="0dp">
<shape android:shape="rectangle">
<solid android:color="#6fdc8c" />
</shape>
</item>
</layer-list>
I need it like below image.
I have tried to add the corners tag inside shape but it didn't work. Hope my query is clear. Thanks in advance.
Here is the full code for your view
<stroke
android:width="25px"
android:color="#android:color/transparent" />
<solid android:color="#android:color/transparent" />
<corners android:radius="10dp" />
</shape>
</item>
<item
android:width="7dp"
android:bottom="0dp"
android:start="0dp"
android:top="200dp">
<shape android:shape="rectangle">
<corners android:bottomLeftRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:width="7dp"
android:bottom="200dp"
android:top="0dp">
<shape android:shape="rectangle">
<corners android:topLeftRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:width="7dp"
android:bottom="0dp"
android:gravity="right"
android:top="200dp">
<shape android:shape="rectangle">
<corners android:bottomRightRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:width="7dp"
android:bottom="200dp"
android:gravity="right"
android:top="0dp">
<shape android:shape="rectangle">
<corners android:topRightRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="7dp"
android:gravity="top"
android:left="0dp"
android:right="200dp"
android:top="-1dp">
<shape android:shape="rectangle">
<corners android:topLeftRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="7dp"
android:gravity="top"
android:left="200dp"
android:right="0dp"
android:top="-1dp">
<shape android:shape="rectangle">
<corners android:topRightRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="7dp"
android:bottom="0dp"
android:gravity="bottom"
android:left="0dp"
android:right="200dp">
<shape android:shape="rectangle">
<corners android:bottomLeftRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="7dp"
android:gravity="bottom"
android:left="200dp"
android:right="0dp">
<shape android:shape="rectangle">
<corners android:bottomRightRadius="20dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
OUTPUT
try this code
<item
android:width="8dp"
android:bottom="0dp"
android:gravity="right"
android:top="200dp">
<shape android:shape="rectangle">
<corners android:bottomRightRadius="10dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
<item
android:height="8dp"
android:gravity="bottom"
android:left="200dp"
android:right="0dp">
<shape android:shape="rectangle">
<corners android:bottomRightRadius="10dp" />
<solid android:color="#6fdc8c" />
</shape>
</item>
How to achieve this kind of shadow using Material CardView. The shadow is only at the bottom not any other side.
app:cardElevation="10dp". Try this on your XML file
Remove elevation and add this xml as custom background of cardview.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<padding android:top="0.5dp" android:right="0.5dp" android:bottom="1dp"
android:left="0.5dp" />
<solid android:color="#10CCCCCC" />
<corners android:radius="8dp" />
</shape>
</item>
<item>
<shape>
<padding android:top="0.5dp" android:right="0dp" android:bottom="1dp"
android:left="0.5dp" />
<solid android:color="#10CCCCCC" />
<corners android:radius="7dp" />
</shape>
</item>
<item>
<shape>
<padding android:top="1dp" android:right="1dp" android:bottom="1dp"
android:left="1dp" />
<solid android:color="#20CCCCCC" />
<corners android:radius="6dp" />
</shape>
</item>
<item>
<shape>
<padding android:top="0dp" android:right="0dp" android:bottom="1dp"
android:left="0dp" />
<solid android:color="#30CCCCCC" />
<corners android:radius="5dp" />
</shape>
</item>
<item>
<shape>
<padding android:top="0dp" android:right="0dp" android:bottom="1dp"
android:left="0dp" />
<solid android:color="#40CCCCCC" />
<corners android:radius="4dp" />
</shape>
</item>
<item>
<shape>
<padding android:top="0dp" android:right="0dp" android:bottom="1dp"
android:left="0dp" />
<solid android:color="#50CCCCCC" />
<corners android:radius="3dp" />
</shape>
</item>
<item>
<shape>
<padding android:top="0dp" android:right="0.1dp" android:bottom="0.5dp"
android:left="0.1dp" />
<solid android:color="#60CCCCCC" />
<corners android:radius="3dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#ffffff" />
<corners android:radius="3dp" />
</shape>
</item>
How to create such button with shadow:
I don't know how to modify this button drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape android:shape="rectangle">
<gradient android:angle="90" android:startColor="#0F9D58" android:endColor="#0F9D58" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:top="10dp" android:left="20dp" android:right="20dp" />
</shape>
</item>
Thanks!
UPDATE. Finally , the code should be as follows:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:left="5dp" android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#0F4858" />
</shape>
</item>
<item android:bottom="2dp" android:left="0dp" android:right="0dp">
<shape>
<gradient android:angle="270"
android:endColor="#0F9D58" android:startColor="#0F9D58" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
Read this thread
Basically, you need create a xml for your custom button, like:
button_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
And now, you can use it, doing reference to the file with:
<Button
android:background="#drawable/button_selector"
...
..
/>
How we can draw a rectangle shape like below image for setting as linear layout back ground?
is it possible to have this with xml shape or I must use a png image?!
Your shape is ready
<?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="14dp"
/>
<solid
android:color="#FFFFFF"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="10dp"
android:height="10dp"
/>
<stroke
android:width="2dp"
android:color="#42929d"
/>
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp">
<shape android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<solid
android:color="#FFFFFF"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="10dp"
android:height="10dp"
/>
<stroke
android:width="2dp"
android:color="#42929d"
/>
</shape>
</item>
</layer-list>
OutPut:
I am trying to use layer-list to create a gradient stroke (i.e. perimeter/border) as the background of my view. But it's not working.
Here is my code
<?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:centerColor="#FFFFFFFF"
android:endColor="#FFCCCCCC"
android:startColor="#FFCCCCCC"
android:type="linear" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#F0F1F3" />
<margin
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
</item>
</layer-list>
The first item is not visible at all. only the second item fills the screen. Any thoughts on how to fix this?
Maybe this can be of use, it create some shadow effect
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape>
<corners android:radius="12dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#00CCCCCC" />
</shape>
</item>
<item>
<shape>
<corners android:radius="12dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#10CCCCCC" />
</shape>
</item>
<item>
<shape>
<corners android:radius="12dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#20CCCCCC" />
</shape>
</item>
<item>
<shape>
<corners android:radius="12dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#30CCCCCC" />
</shape>
</item>
<item>
<shape>
<corners android:radius="12dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<solid android:color="#50CCCCCC" />
</shape>
</item>
<!-- Background -->
<item>
<shape>
<solid android:color="#android:color/black" />
<corners android:radius="12dp" />
</shape>
</item>
</layer-list>
You can try something like this
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:innerRadius="80dp"
android:shape="ring"
android:thickness="20dp"
android:useLevel="false">
<size
android:width="200dp"
android:height="200dp" />
<gradient
android:endColor="#00ff0000"
android:gradientRadius="200"
android:startColor="#ffff0000"
android:type="radial" />
</shape>
</item>
<item
android:bottom="20dp"
android:left="20dp"
android:right="20dp"
android:top="20dp">
<shape android:shape="oval">
<stroke
android:width="1dp"
android:color="#ff0000" />
</shape>
</item>
</layer-list>