Search code examples
androidandroid-layoutbackground-colorshadow

Android shadow color for layout


I have developed a listView for my app. My UI is simple flat UI, here is a snapshot:

enter image description here

when I searched internet for better interfaces I found this for example: enter image description here

As you see in this sample, background colors have shadows at the bottom. Is there a way that I can color my Layout background like this? Thanks in advanced.


Solution

  • In order to achieve a shadow effect I'd guess that it's better to use a layer-list with two items, one with the solid color and the second item would be a gradient coming from transparent to a black color with an alpha value.

    Here's how this would look like (needs to be placed in res/drawable/):

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="#ff33b5e5" />
            </shape>
        </item>
        <item>
            <shape android:shape="rectangle">
                <gradient
                    android:angle="-90"
                    android:endColor="#90000000"
                    android:startColor="@android:color/transparent" />
            </shape>
        </item>
    </layer-list>
    

    Doing it this way, you won't need to "search" for a darker color of your solid color all the time.

    Output would look like this:

    enter image description here