Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273456
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:56:02+00:00 2026-05-17T18:56:02+00:00

If I draw a round rect shape by code I can use setShadowLayer to

  • 0

If I draw a round rect shape by code I can use setShadowLayer to get a shadow drawn for the shape. Is there an equivalent when defining shapes in XML?

The following example draws a round rect background to a shape. What would I need to add to get a shadow added to the shape? Is it even possible using XML?

shape_test.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#8067BF6A"/>    
    <stroke android:width="3dp" android:color="#80000000" />
    <padding android:left="1dp"
      android:top="1dp"
      android:right="1dp"
      android:bottom="1dp" /> 
    <corners android:bottomRightRadius="7dp"
      android:bottomLeftRadius="7dp"
      android:topLeftRadius="7dp"
      android:topRightRadius="7dp"/> 
</shape>

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:padding="10dp"
 android:background="#ffdddddd"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <Button android:background="@drawable/shape_test"
 android:padding="5dp"
 android:textStyle="bold"
 android:textSize="28sp"
 android:text="Hello"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" />
</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:56:02+00:00Added an answer on May 17, 2026 at 6:56 pm

    Using XML, there’s no real way to do this that I know of. I’ve seen some suggestions of making a second box of the same shape behind the item, and just filling it with black, but I don’t feel that’s a good solution. I’ve been trying to find a way to do this myself for a while.

    If it helps, here’s a link to a similar question I posted, along with some code. I got it working for some images, but it still seems to have trouble finding the alpha channel sometimes. Basically, I’ve overridden ImageView and put this in the onDraw() method:

    @Override 
    protected void onDraw(Canvas canvas)  
    { 
        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.omen); 
        Paint paint = new Paint(); 
        paint.setAntiAlias(true); 
        paint.setShadowLayer(5.5f, 6.0f, 6.0f, Color.BLACK); 
        canvas.drawColor(Color.GRAY); 
        canvas.drawRect(50, 50, 50 + bmp.getWidth(), 50 + bmp.getHeight(), paint); 
        canvas.drawBitmap(bmp, 50, 50, null);        
    } 
    

    That was just testing, though, so obviously a lot of the parameters would have to be more generic. I haven’t had a lot of time to work on it lately though, but maybe this will help you find your answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a shape on a Canvas and get information about the
I'm trying to draw a polygon using c# and directx All I get is
How can I draw something in JPanel that will stay the same and not
How can i draw a dotted line in .NET/WinForms/GDI+? Pen p = new Pen
I am trying to draw a drop shadow underneath an image to which I
I am trying to draw a white circle with the following code: mPaint.setColor(0xFFFFFFFF); canvas.drawCircle(x,
How do you draw a custom button next to the minimize, maximize and close
I'm trying to draw a graph on an ASP webpage. I'm hoping an API
I need to draw some simple network topology charts, suggestions of some good tools
What are ways to draw animations in C++? GDI+? OpenGL? Would you recommend a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.