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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:59:28+00:00 2026-06-08T18:59:28+00:00

I have a screen where multiple Buttons use the same background Drawable. I have

  • 0

I have a screen where multiple Buttons use the same background Drawable. I have reusable code I use in various projects to add an OnTouch listener that adds a gray color filter while a button is being touched. That usually works fine, but in this case ALL the buttons are tinted when any of them is pressed.

I see an explanation in http://developer.android.com/guide/topics/graphics/2d-graphics.html:

Note: Each unique resource in your project can maintain only one
state, no matter how many different objects you may instantiate for
it. For example, if you instantiate two Drawable objects from the same
image resource, then change a property (such as the alpha) for one of
the Drawables, then it will also affect the other.

The suggested solution is to use a TweenAnimation, which does not seem to work with color filters.

I also saw Android: Cloning a drawable in order to make a StateListDrawable with filters which suggests using drawable.getConstantState().newDrawable(). This does not seem to make a difference. I’m guessing that as long as the same physical image file is used, all Drawables will be affected by a change to any other Drawable using the same resource.

What solution is there, other than creating a second background image to show the pressed state? It would be nice to have a simple programmatic solution I can add to my code and use in every project.

  • 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-08T18:59:30+00:00Added an answer on June 8, 2026 at 6:59 pm

    Example that should work for you:

    Drawable buttonBackground = context.getResources().getDrawable(R.drawable.bg);
    buttonBackground = buttonBackground.mutate();
    
    //Set your filter here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use same widgets(buttons,editext,textviews) with same properties like width,height,textColor,size etc in multiple
i have a screen with multiple little widgets (all with different divs around them).
My app needs to have multiple screen e.g. one login page then another page
I need my application run in multiple screen resolutions. Currently I have specified all
In my iPad Application I have multiple views on a screen. What I want
i have a screen and it is i want the buttons to put under
I am creating an application that will have multiple images on the screen, these
I use an MVC template to allow the user to add multiple addresses. They
I have some problem with multiple screen support, I work with dp(dpi) for specify
I have multiple buttons, each having a 32x32 pixels PNG image. The strange thing

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.