richardnixonthethird
richardnixonthethird

Reputation: 345

setBackgroundDrawable is not changing the LayoutBackground

I have seen several instances of this question on here and the provided solutions dont seem to work.

My goal : Update the background of my LinearLayout depending on what color i get back from a database query.

What I have so far:

if(teamc=="black"){
    drawable = this.getResources().getDrawable(R.drawable.blackbackground);
    Toast.makeText(TeamActivity.this,teamc, Toast.LENGTH_LONG).show();
    teamColor.setBackgroundDrawable(drawable);
    }

Team color is defined as

teamColor = (LinearLayout) findViewById(R.id.teamcolor);

What is happening is that the Toast is appearing just fine but the background is not changing.

Any help would be appreciated.

Upvotes: 1

Views: 6276

Answers (5)

TlonXP
TlonXP

Reputation: 3485

In my application I use a WebView to display a web page, when the page is scale fits well but now are whites spaces on each side of the page, I can change the background to black color??

Upvotes: 0

Arun Badole
Arun Badole

Reputation: 11097

It is really strange if Toast is working but background is not changing.

Try using teamc.equals("black"){}

or

teamColor.setBackgroundResource(R.drawable.blackbackground);

Upvotes: 2

Cata
Cata

Reputation: 11211

Are you sure that that toast is showing and not other toast? Because you try to check a String if it's equal to another String by using == operator and that is wrong.

You have to use .equals() method to make a comparison between two Objects.

Upvotes: 2

Pratik
Pratik

Reputation: 30855

call the invalidate() of the LinearLayout using teamColor object after set the background

teamColor.invalidate();

Upvotes: 0

Dany's
Dany's

Reputation: 928

try to make directly teamColor.setBackgroundResource(R.drawable.blackbackground);

Upvotes: 0

Related Questions