简体   繁体   中英

Android view background color in runtime

I would like to set the background color of some views in run-time (I'm getting the color from a server request). All these views have a default color, and if I get a color from the server I would like to change it all at once. Is there a way it will happen automatically by setting a parameter, or the only way I can do it is by calling setBackground for each of the views. Thanks

Create for every view type a class that extends a corresponding class( BkgEditText extends EditText or BkgView extends View ) and change the background color to the custom one in constructor. This way, the view will have the desired color when added from xml or code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM