How can I set the background color of an Activity to white programatically?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How can I create this custom Bottom Navigation on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
I prefer coloring by theme
In other words, "android:background" is the tag in the XML you want to change.
If you need to dynamically update the background value, see the following:
Exercise: Change background color, by SeekBar
I was having a similar problem, and I followed the steps mentioned in the answers given above. I'll share what worked for me.
I was using a RecyclerView, and had set a background color for the item. However, it looked weird when the number of items didn't fit the screen
My initial layout
I then used the function
And called the function
setActivityBackgroundColor(R.color.colorAccent);
in my code in another function. That led to this layout. Pretty weird.I finally fixed it by following what KitKat suggested.
This finally fixed it.
EDIT: The solution started throwing an error if the RecyclerView was not populated. In that case, I set a flag to check if the view is empty or not.
It works like a charm now.
Add this single line in your activity, after
setContentView()
callworked for me. thank you.