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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:41:52+00:00 2026-05-28T17:41:52+00:00

In Android, I have a button that contains an image and text. When the

  • 0

In Android, I have a button that contains an image and text. When the button is disabled, the text is automatically grayed out, but the image stays the same. Is it possible to have the image dimmed when the button is disabled without having two separate images?

  • 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-28T17:41:54+00:00Added an answer on May 28, 2026 at 5:41 pm

    Finally got it!

    I haven’t found a way to do this by setting the image in XML, so have to set it in the code. Here’s what I got that works:

    Button btnObjects = (Button)this.findViewById(R.id.button_objects);
    Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.button_image_objects);
    if( <button needs to be disabled> )
    {
        btnObjects.setEnabled(false);
        bm = adjustOpacity(bm, 128);
    }
    else
    {
        btnObjects.setEnabled(true);
    }
    btnObjects.setCompoundDrawablesWithIntrinsicBounds(null, new BitmapDrawable(bm), null, null);
    
    //and here's where the magic happens
    private Bitmap adjustOpacity(Bitmap bitmap, int opacity)
    {
        //make sure bitmap is mutable (copy of needed)
        Bitmap mutableBitmap = bitmap.isMutable()
                               ? bitmap
                               : bitmap.copy(Bitmap.Config.ARGB_8888, true);
    
        //draw the bitmap into a canvas
        Canvas canvas = new Canvas(mutableBitmap);
    
        //create a color with the specified opacity
        int colour = (opacity & 0xFF) << 24;
    
        //draw the colour over the bitmap using PorterDuff mode DST_IN
        canvas.drawColor(colour, PorterDuff.Mode.DST_IN);
    
        //now return the adjusted bitmap
        return mutableBitmap;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I' have a view that contains several textViews an ImageView and a Button .
On Android, I would like to create a button that contains some other Views.
I have an application that contains two Activities with <intent-filter> <action android:name=android.intent.action.MAIN/> <category android:name=android.intent.category.LAUNCHER/>
Cant figure this out (am a noob) but I have a default activity that
I have an android application with a background thread that contains a socket connection
I have an Android application that contains two Activities . Activity A has a
in my android app, I have a button that leads to an activity which
I have a header for a list that contains two image buttons. I want
I have a custom list view which contains two text views and on button.

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.