How to Provide Shadow to Button

How to provide shadow to Button

Use this approach to get your desired look.

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>

</selector>

And in your xml layout:

<Button
android:background="@drawable/button_selector"
...
..
/>

How to add a shadow around a button in Flutter?

You can add a pink shadow to the Container:

Container(
height: 60,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color.fromRGBO(255, 143, 158, 1),
Color.fromRGBO(255, 188, 143, 1),
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: const BorderRadius.all(
Radius.circular(25.0),
),
boxShadow: [
BoxShadow(
color: Colors.pink.withOpacity(0.2),
spreadRadius: 4,
blurRadius: 10,
offset: Offset(0, 3),
)
]
),
child: Center(
child: GestureDetector(
onTap: () {},
child: Text(
'Create Account',
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: "Netflix",
fontWeight: FontWeight.w600,
fontSize: 18,
letterSpacing: 0.0,
color: Colors.white,
),
),
),
),
),

Note: I also changed the gradient colors to make it look more like the picture.

Result:

res

Add spreading Shadow to the bottom of button Android

Create your own xml file in drawable folder and set in your button background.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
android:bottom="-6dp"
android:drawable="@android:drawable/dialog_holo_light_frame"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">

</item>

<item
android:bottom="-6dp"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">

<shape android:shape="rectangle">
<solid android:color="@color/transparent" />
</shape>
</item>
</layer-list>

How to set button have image and shadow?

1. use ImageButton

try this you can use ImageButton :- Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states.

 <ImageButton
android:id="@+id/btnMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/btnMain_description"
android:elevation="10dp"
android:background="@android:drawable/dialog_holo_light_fram‌​e"
android:scaleType="centerInside"
android:src="@drawable/IMage"
/>

2. user CardVirew
or you can try this add your button inside card view like this

compile this dependencies

compile 'com.android.support:cardview-v7:25.3.1'

layout like this

    <android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="10dp">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/disha"
android:text="@string/app_name" />
</android.support.v7.widget.CardView>

ask me in case of any query

how to set up shadow in a button active css

It comes from the default properties the browser is giving the button. It is the border-style property.

If you use Chrome Developer Tools, the default styling is in italic and there you can see border-style.





.btn {
border-style: outset;
}

.btn:hover {
border-style: inset;
}
<button class="btn">Click me</button>

How to add a blurred drop shadow to a button?

Well i found the solution: we need to create 9.png with blurred drop-shadow via this generator and pass it to drawable layer-list that contain button background gradient:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/blurred_9_path_png" />
<item>
<shape android:shape="rectangle" android:padding="10dp">
<corners android:radius="45dp" />
<gradient
android:angle="45"
android:endColor="@color/facebook_btn_fill_grad2"
android:startColor="@color/facebook_btn_fill_grad1"
android:type="linear" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
</item>

</layer-list>

After that we can use such drawables with different 9.path blurred shadow to create selector.

how to create a button with shadow

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"
...
..
/>


Related Topics



Leave a reply



Submit