Kevin
Kevin

Reputation: 1

Android dynamic background

I am somewhat of a new android developer and have a question regarding changing the background dynamically at runtime.

What I want to do is set a background color in a LinearLayout Tag, and later change that background color in my activity class. This code below is not working. Am I missing something or is this the wrong approach for trying to change the background color in a linear layout

LinearLayout lv = (LinearLayout)findViewById(R.id.ChoiceLayout);
lv.setBackgroundColor(0x000080);

Thanks in advance

Upvotes: 0

Views: 2560

Answers (3)

shailendra
shailendra

Reputation: 21

already answered in another post , unfortunately i don't know that link but know the solution.

use

lv.setBackgroungColor(GetResources().getColor(int color));

Upvotes: 0

Paul Turchenko
Paul Turchenko

Reputation: 831

First thing I've noticed is that your color has ALPHA = 0x00. Which makes it transparent. Try changing to

lv.setBackgroundColor(0xFF000080);

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1006554

AFAIK, that should work fine. Use hierarchyviewer to try to diagnose what is going wrong.

Upvotes: 0

Related Questions