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 6005989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:28:34+00:00 2026-05-23T01:28:34+00:00

I want to draw a number on an existing drawable. Like the unread count

  • 0

I want to draw a number on an existing drawable. Like the unread count at an email icon. The drawable is the top icon of a button. This is my code:

BitmapDrawable d = (BitmapDrawable) button.getCompoundDrawables()[1];
if(d != null) {
    Bitmap src = d.getBitmap();
    Bitmap b = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    Canvas c = new Canvas(b);

    Paint p = new Paint();
    p.setAntiAlias(true);
    p.setStrokeWidth(1);
    p.setStyle(Style.FILL_AND_STROKE);
    p.setColor(Color.rgb(254, 0, 1));

    c.drawBitmap(src, 0, 0, p);
    c.drawCircle(b.getWidth()-5, 5, 5, p);
    button.setCompoundDrawables(null, new BitmapDrawable(b), null, null);
}

The resulting drawable is emtpy. Is there something wrong with this code?

Thanks in advance.

  • 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-23T01:28:34+00:00Added an answer on May 23, 2026 at 1:28 am

    The new bitmap has to call setBounds(…)

    BitmapDrawable dn = new BitmapDrawable(b);
    dn.setBounds(d.getBounds());
    button.setCompoundDrawables(null, dn, null, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem. I want to draw a random String something like this
I want to draw a number centered inside a wx.EmptyBitmap. How can I do
I want to draw a table dynamically on html page. Number of rows, number
I want to draw a widget (in this example, a canvas) and then remove
I want to draw the number badge as shown in the above image on
I would like to draw a circle with an initial degree and I want
I want to animate motion of a number of squares. In this example i
I want to draw an alpha mask image in code. Right now I do:
Just like hold on in Matlab. I met this problem when i want to
I want to draw a variable number of equidistant points on a HTML5 canvas

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.