I want create in button with light button border with little 3D shade on edges like this
create an xml in your drawable
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="2dp" android:top="2dp">
<shape>
<corners android:radius="0dp" />
<solid android:color="#A09D9D"
/>
</shape>
</item>
<item android:bottom="1dp" android:left="1dp">
<shape>
<gradient android:angle="270"
android:endColor="#color/white"
android:startColor="#color/white" />
<stroke
android:width="0.5dp"
android:color="#CBCBC9" />
<corners
android:radius="0dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
and use this xml as your button background
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#color/white" />
<stroke android:width="1dip" android:color="#color/gray">
</stroke>
</shape>
Set this Xml on background
Related
I just wat to create a button as shown in the image. But I am not able to make the round edges at the top corners. How we can do that..please help.
<item>
<shape android:shape="rectangle">
<solid android:color="#A32CB386" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:bottom="5px">
<shape android:shape="rectangle">
<solid android:color="#36885B" />
</shape>
</item>
Your drawable file. Let's say bg_sign_in.xml
<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="5dp" />
<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" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
</item>
Apply the following in your xml
android:background="#drawable/bg_sign_in"
Output:
You can use something like:
<com.google.android.material.button.MaterialButton
android:background="#drawable/test"
app:backgroundTint="#null"
/>
with:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<item>
<!-- bottom shadow -->
<shape>
<solid android:color="#2CB386"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item
android:bottom="10px"
>
<shape>
<solid android:color="#36885B"/>
<corners
android:radius="5dp"/>
</shape>
</item>
</layer-list>
</item>
<item android:state_pressed="true">
<layer-list>
<!-- .... -->
</layer-list>
</item>
</selector>
Actually I made a drawable resource file for the background of my layout. I want that my layout should have 3 sides of same color and one side of different color.
In this piece of code, all sides of layout has red color. I want 3 should have red color and one should have white color.
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<stroke android:color="#color/colorLightRed" android:width="1dp">
</stroke>
</shape>
You can try something like this . Its not the best solution i guess ..
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="-2dp">
<shape>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<stroke
android:width="1dp"
android:color="#color/black30">
</stroke>
</shape>
</item>
<item
android:bottom="-2dp"
android:left="-2dp"
android:top="-2dp">
<shape>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<stroke
android:width="1dp"
android:color="#color/green">
</stroke>
</shape>
</item>
You have to create the Layer list in order to do that.Add your colors for Bottom,Top,Left and for right side.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<!-- Set the border color of your layout here -->
<solid android:color="#3AFB03" />
</shape>
</item>
<!-- This is for border bottom but
you can change this according to your need -->
<item android:right="4dp" >
<shape
android:shape="rectangle">
<!-- Set the background color of your layout here -->
<solid android:color="#000000" />
</shape>
</item>
<item android:left="4dp">
<shape android:shape="rectangle">
<solid android:color="#FFEB3B"/>
</shape>
</item>
</layer-list>
Try this way
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="2dp"
android:right="2dp">
<shape android:shape="rectangle">
<solid android:color="#00BCD4" />
</shape>
</item>
<item
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#FF0000" />
</shape>
</item>
<item
android:left="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFFF00" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp">
<shape android:shape="rectangle">
<solid android:color="#4CAF50" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle">
<solid android:color="#00BCD4" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
</layer-list>
OUTPUT
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>
I am tring below code for make shape look like below image, is that possible to make below screenshot by only layer-list concept?
What i hv tried ?
This is my code :
<item>
<shape android:shape="rectangle" >
<solid android:color="#00f" />
<padding android:bottom="2dp" />
</shape>
</item>
<item android:bottom="10dp">
<shape android:shape="rectangle" >
<solid android:color="#fff" />
<padding
android:left="2dp"
android:right="2dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#fff" />
</shape>
</item>
<item>
<shape>
<!-- set the shadow color here -->
<stroke
android:width="2dp"
android:color="#color/generic_shadow_color" />
<!-- setting the thickness of shadow (positive value will give shadow on that side) -->
<padding
android:bottom="2dp"
android:left="-1dp"
android:right="2dp"
android:top="-1dp" />
<corners android:radius="7dp" />
</shape>
</item>
<!-- Background -->
<item>
<shape>
<solid android:color="#color/generic_shadow_color" />
<corners android:radius="7dp" />
</shape>
</item>
Result Shape i want is :
My question is really simple. That is about Button attrs.
I want to make Button which has only Top stoke. What can I set in layout xml ??
My xml file is
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<shape>
<solid android:color="#android:color/transparent"/>
<stroke android:width="1dp" android:color="#color/btn_disable"
android:dashWidth="1dp" android:dashGap="0dp"/>
<padding android:left="9dp" android:top="2dp"
android:right="9dp" android:bottom="2dp"/>
<corners android:radius="#dimen/btn_radius" />
</shape>
</item>
<item android:state_pressed="true" >
<shape>
<solid android:color="#color/white_pressed"/>
<stroke android:width="1dp" android:color="#color/mint"
android:dashWidth="1dp" android:dashGap="0dp"/>
<padding android:left="9dp" android:top="2dp"
android:right="9dp" android:bottom="2dp"/>
<corners android:radius="#dimen/btn_radius" />
</shape>
</item>
<item>
<shape>
<solid android:color="#null"/>
<stroke android:width="1dp" android:color="#color/mint"
android:dashWidth="1dp" android:dashGap="0dp" />
<corners android:radius="#dimen/btn_radius" />
</shape>
</item>
</selector>
I cannot determine the exact shape you are looking for, but judging that you only want the top stroke, hide all other strokes, you can use a layer-list to achieve this.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="your_stroke_colour" />
<corners
android:radius="your_radius" />
</shape>
</item>
<item
android:top="1dp"
android:bottom="0dp"
android:left="0dp"
android:right="0dp">
<shape android:shape="rectangle">
<solid android:color="your_color" />
<corners
android:radius="your_radius" />
</shape>
</item>
</layer-list>