开发者

Android dynamic background

开发者 https://www.devze.com 2023-01-10 06:49 出处:网络
I am somewhat of a new android developer and have a question regarding changing the background dynamically at runtime.

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

Wh开发者_如何转开发at 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


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

lv.setBackgroundColor(0xFF000080);


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


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

use

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号