简体   繁体   中英

How to add inner shadow effect in drawable android?

I want to add inner shadow effect into my drawable file like this.

在此处输入图像描述

Below is my drawable file. I want to achieve shadow inside the drawable file as you can see above. What changes should i make to achieve this?

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <item
        android:bottom="@dimen/_3sdp"
        android:left="@dimen/_8sdp"
        android:right="@dimen/_8sdp"
        android:top="@dimen/_3sdp">

        <shape>

            <corners android:radius="@dimen/_75sdp" />

            <padding android:bottom="@dimen/_8sdp"
                android:top="@dimen/_8sdp" />

            <solid android:color="@color/leave_msg_color" />

        </shape>

    </item>

</layer-list>

You can make many item inside your layer-list to produce shadow effect inside check this one out Add shadow to custom shape on Android .

You just need to change some values to achieve your wanted output. make the radius to get oval form and the values of colors.

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:top="@dimen/size_point5dp"
            android:left="@dimen/size_point5dp"
            android:right="@dimen/size_point5dp"
            android:bottom="@dimen/size_point5dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/blue_E7F1FF"/>
            <corners android:radius="8dp"/>
        </shape>

    </item>

    <!--  left shadow -->
    <item>
        <shape android:shape="rectangle">
            <gradient
                    android:angle="180"
                    android:centerColor="#00FF0000"
                    android:centerX="0.98"
                    android:endColor="#5C000000"
                    android:startColor="#00FF0000" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <!--  right shadow -->
    <item>
        <shape android:shape="rectangle">
            <gradient
                    android:angle="360"
                    android:centerColor="#00FF0000"
                    android:centerX="0.98"
                    android:endColor="#5C000000"
                    android:startColor="#00FF0000" />
            <corners android:radius="8dp" />
        </shape>
    </item>
    <!--  top shadow -->
    <item>
        <shape android:shape="rectangle">
            <gradient
                    android:angle="270"
                    android:centerColor="#00FF0000"
                    android:centerY="0.1"
                    android:endColor="#00FF0000"
                    android:startColor="#6B000000" />
            <corners android:radius="8dp" />
        </shape>
    </item>
 <!--  bottom shadow -->
    <item>
        <shape android:shape="rectangle">
            <gradient
                    android:angle="90"
                    android:centerColor="#00FF0000"
                    android:centerY="0.1"
                    android:endColor="#00FF0000"
                    android:startColor="#6B000000" />
            <corners android:radius="8dp" />
        </shape>
    </item>
</layer-list>

The image would look like image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM