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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:50:41+00:00 2026-06-02T02:50:41+00:00

I want set a background colour to an ImageView, when the imageview has an

  • 0

I want set a background colour to an ImageView, when the imageview has an image resource, it works and i get my background colour but when the image view don’t have an image resource, SetBackgroundColor don’t work and do nothing, this is my code :

xml Layout :

       <ImageView android:layout_centerHorizontal="true"
        android:id="@+id/favor_item_image" 
        android:layout_alignParentTop="true" android:layout_height="wrap_content"
        android:layout_width="match_parent" android:adjustViewBounds="true"/>

java code :

       ImageView favorImage = (ImageView) MyView.findViewById(R.id.favor_item_image);  
       //favorImage.setImageResource(R.drawable.btndelete);
       favorImage.setBackgroundColor(Color.argb(255,255,0,0));

So, when i comment this line : //favorImage.setImageResource(R.drawable.btndelete); i cannot set the image view background colour , but when i uncomment this line, setBackgroundColor works fine.

any help please.
Thanks

  • 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-02T02:50:42+00:00Added an answer on June 2, 2026 at 2:50 am

    The reason you are not seeing anything is because you have the layout_height set to wrap_content. When you do not have an image set on the ImageView wrap_content sets the height to 0. If you want the color to display without an image you will have to set the layout_height to an actual value such as 50dp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set an image to have a transparent background, but I do
I want to set a background of a View with a tiled bitmap, but
i want have an image and i want to set it as a background
In XCode 4.2, I want to set a view's background colour to a particular
I want to change background color of image view randomly i don't want to
I want to color to background of an image View when it get pressed.
I have developed the application in which i want to set the background color
I want set Listbox background to transparent but not working Is there any idea?
I want to set background image to right and top of my span because
I want to set a background image for a div, in a way that

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.