I am sure that it is not possible to do this only programmatically, unless you want to use an overly complex method using OpenGL.
Instead, you can try the following:
Make a 9-patch png, which is a box with an external shadow around it, and the content labels (on the right and bottom) are inside the white part. Then set this against the background of any element to which you want to add a shadow. Here is one that found what should give you an idea of ββwhat to use:
If you are not familiar with 9-patch images read about them here

Note. You need to save it as <filename>.9.png . This 9.png very important. If you omit 9 , this will not work.
You can delete the specified image in draw9patch and adjust the sides if you need more or less spaces.
source share