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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:19:27+00:00 2026-06-13T08:19:27+00:00

How can I dynamically update the icon for an ActionBar MenuItem to show a

  • 0

How can I dynamically update the icon for an ActionBar MenuItem to show a ‘red badge’ with a number? (conceptually similar to “unread message count’)

I’m using ActionBarSherlock in my Android application, targeting API level 10+. My application is for mobile data capture and, sometimes, the user cannot immediately submit new data but must save it locally on the phone (e.g. when connectivity is poor).

Whenever there are ‘unsubmitted’ items stored locally on the phone, I’d like to show the user a menu item (in the Action Bar) so that they can click over to the UnsubmittedItems activity and trigger an upload manually.

Ideally, this menu item will have some graphical representation of the number of unsubmitted items (similar to how an email or sms app shows the number of unread messages as a badge). Currently, I’m just doing:

unsubmittedMenuItem.setTitle( Integer.toString(numUnsubmitted) );

And this works, but two issues: I’d prefer to use the Icon and keep the Title as something intelligible (“Unsubmitted”) and, also, I’d love to have some custom layout or design here, such as a red circle background behind the number.

Thoughts on how to accomplish this? So far my research suggest two possibilities:

  1. Use a level list drawable that is precreated for some range of numbers (e.g. 1, 2, 3… 10+) and then unsubmittedMenuItem.getIcon().setLevel( numUnsubmitted )
  2. Build the entire bitmap entirely dynamically, using the Bitmap and Canvas APIs

These are similar in the sense that I’m rendering the text into a bitmap (either offline like #1 or on the fly like #2) but it would be great to leverage the ‘native’ text rendering of the ActionBar if possible and simply insert a red circle behind it like in a TextView.

Is there some way to set a custom layout just for the icon drawable? (NOT a full actionLayout, just for the icon?)

  • 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-06-13T08:19:28+00:00Added an answer on June 13, 2026 at 8:19 am

    There are a lot of ways to do this:

    1. Use LayerDrawable and stack badge images on top of your icon image.
    2. Write a custom class which extends from Drawable and draws the icon and badge manually.
    3. Use a custom action item view with your icon in an ImageView with a TextView overlay for the badge.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a picture in res/drawable directory: res/drawable/picture.jpeg. Can I dynamically update this picture.jpeg
I am trying to figure out how I can update my sql query dynamically.
How can you dynamically update the datasource of a WPF ToolKit chartcontrol? In the
how can I (dynamically) update a ip address for server whose ip changes and
How can i update the following JSON object dynamically using javascript or Jquery? var
How can I use JFreeChart to dynamically update a chart's appearance after it's been
I have a page where the user can dynamically add file upload boxes. Adding
I am writing a container framework that can dynamically deploy a Jar file containing
Does anyone know how I can Dynamically create an installation package that installs files
The problem in my case is I can dynamically add / remove input boxes,

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.