Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set BackgroundColor on ImageView on Android?

I tried a couple things and nothing is working... I'm trying to change the BackgroundColor on a ImageView on Android, but nothing happens...

Here is my xml:

<ImageView    android:id="@+id/imageView1"    android:layout_width="350dp"    android:layout_height="550dp"    android:layout_above="@+id/btnInfo"    android:layout_alignLeft="@+id/fundo"    android:layout_alignRight="@+id/btnInfo"    android:layout_alignTop="@+id/fundo"    android:layout_centerHorizontal="true"    android:contentDescription="@string/backgroundMain" /> 

And the code:

public void onStart()     {         super.onStart();         Log.d("Teste", "In the onStart() event 5");          ImageView backgroundImg = (ImageView) findViewById(R.id.imageView1);         backgroundImg.setBackgroundColor(Color.rgb(255, 255, 255));     } 

What am I missing?

like image 588
CarinaPilar Avatar asked Oct 19 '13 01:10

CarinaPilar


People also ask

What is the ImageView in android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling. To learn more about Drawables, see: Drawable Resources.


2 Answers

There's nothing wrong with your code. But I would prefer doing this through xml , This will also solve your problem. Just add this in your ImageView tag.

android:background="@android:color/black" 
like image 22
ayon Avatar answered Sep 21 '22 21:09

ayon


RGB:255, 255, 255 is the color code for WHITE. Since your parent layout background color is also white you won't see the difference.

Try changing color like

backgroundImg.setBackgroundColor(Color.rgb(100, 100, 50)); 

Or else change the background color of parent layout.

like image 153
Abhishek V Avatar answered Sep 23 '22 21:09

Abhishek V