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

  • Home
  • SEARCH
  • 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 756641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:16:06+00:00 2026-05-14T15:16:06+00:00

I am trying to create a drawable in code and change the color based

  • 0

I am trying to create a drawable in code and change the color based on some criteria. When I try and set the Drawable as the background of the ImageView it displays but won’t let me set any padding. I realized I need to set the ImageView image via the setImageDrawable() function in order to be able to set the padding.

The problem I am running into is that when I set it via the setImageDrawable() function nothing is displayed.

Here is what I have written:

<?xml version="1.0" encoding="utf-8"?>

            ImageView icon = (ImageView) row.findViewById(R.id.icon);
  ShapeDrawable mDrawable;

  int x = 0;
     int y = 0;
     int width = 50;
     int height = 50;

     float[] outerR = new float[] { 12, 12, 12, 12, 12, 12, 12, 12 };

     mDrawable = new ShapeDrawable(new RoundRectShape(outerR, null, null));
     mDrawable.setBounds(x, y+height, x + width, y);



  switch(position){

  case 0:
   mDrawable.getPaint().setColor(0xffff0000);  //Red
   break;
  case 1:
   mDrawable.getPaint().setColor(0xffff0000);  //Red
   break;
  case 2:
   mDrawable.getPaint().setColor(0xff00c000);  //Green
   break;
  case 3:
   mDrawable.getPaint().setColor(0xff00c000);  //Green
   break;
  case 4:
   mDrawable.getPaint().setColor(0xff0000ff);  //Blue
   break;
  case 5:
   mDrawable.getPaint().setColor(0xff0000ff);  //Blue
   break;
  case 6:
   mDrawable.getPaint().setColor(0xff696969);  //Gray
   break;
  case 7:
   mDrawable.getPaint().setColor(0xff696969);  //Gray
   break;
  case 8:
   mDrawable.getPaint().setColor(0xffffff00);  //Yellow
   break;
  case 9:
   mDrawable.getPaint().setColor(0xff8b4513);  //Brown
   break;
  case 10:
   mDrawable.getPaint().setColor(0xff8b4513);  //Brown
   break;
  case 11:
   mDrawable.getPaint().setColor(0xff8b4513);  //Brown
   break;
  case 12:
   mDrawable.getPaint().setColor(0xffa020f0);  //Purple
   break;
  case 13:
   mDrawable.getPaint().setColor(0xffff0000);  //Red
   break;
  case 14:
   mDrawable.getPaint().setColor(0xffffd700);  //Gold
   break;
  case 15:
   mDrawable.getPaint().setColor(0xffff6600);  //Orange
   break;
  }

     icon.setImageDrawable(mDrawable);
     icon.setPadding(5, 5, 5, 5);

This results in a space for the ImageView but no image.

Thanks,
Rob

  • 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-14T15:16:06+00:00Added an answer on May 14, 2026 at 3:16 pm

    If you implement the draw method of a custom ImageView you can just draw a tint over the image. For a nice rosy sheen try:

        @Override
        protected void onDraw( Canvas canvas ) {
            super.onDraw( canvas );
    
            Rect                frame;
            Paint               paint = new Paint();
    
            paint.setStyle( Style.FILL );
            paint.setARGB( 102 , 255 , 51 , 51 );
            frame = new Rect( 0, 0, getWidth(), getHeight() );
            canvas.drawRect( frame , paint );
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.