jack_the_beast
jack_the_beast

Reputation: 1971

Android: create drop shadow from path

is there a way to create a drop shadow given a drawable with a path like below:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="24.0"
        android:viewportWidth="24.0">
    <path
        android:fillColor="#FFFFFF"
        android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

both xml and programmatically would be good. I tried to do a little reasearch but couldn't find anything.

EDIT: ideally I'll need somenthing reusable with whatever vector. Something like:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        //magic happens
    </item>
    <item>
        <include> my_vector </include>
    </item>
</layer-list>

again, even programattically it's fine, if not better

Upvotes: 5

Views: 4915

Answers (2)

Adil
Adil

Reputation: 812

you can add use like this

    <?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">

<path
    android:fillColor="#ffffff"
    android:pathData="M15 12.28L20.37 18.35L17.36 21.75L12 15.68L6.64 21.75L3.63 18.35L9 12.28L3.63 6.21L6.64 2.81L12 8.88L17.36 2.81L20.37 6.21L15 12.28Z" />
<path
    android:fillColor="#ffffff"
    android:strokeWidth="1"
    android:pathData="M15 12.28L20.37 18.35L17.36 21.75L12 15.68L6.64 21.75L3.63 18.35L9 12.28L3.63 6.21L6.64 2.81L12 8.88L17.36 2.81L20.37 6.21L15 12.28Z" />

Upvotes: 0

PJain
PJain

Reputation: 566

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="24.0"
        android:viewportWidth="24.0">
        <path
            android:fillColor="#A9A9A9"
            android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
    </vector>
</item>
<item>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportHeight="25.0"
        android:viewportWidth="25.0">
        <path
            android:fillColor="#ffffff"
            android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
    </vector>
</item>

please check this code.

Upvotes: 2

Related Questions