I have an app with a simple recyclerview.
The layout is declared as follow
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/some_id" />
</RelativeLayout>
I notice that on different devices, the recyclerView actually had a different background. In newer devices, the background is just white. On older devices, the background is light gray.
In android studio, the background color is blank in the design view.
So my question is, where does this gray color come from? How can I change it universally to white?
I can obviously just add background:white to this particular view. But is there a way to overwrite the system default?
By default each activity in Android has a white background. To change the background color, first add a new color definition to the colors.
To open it go to Tools -> Android -> Theme Editor.
Android default background color
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground">
</RelativeLayout
use
android:background="?android:colorBackground"
What you are seeing is actually the background of the activity, not the recyclerview, which is transparent by default. The color did change a view time per Android version.
You can override this in your app theme.
First define the color in values/colors.xml
<resources>
<color name="background">#FF0000 </color>
</resources>
Create a themes.xml file in res/values that references that color:
<resources>
<style name="MyTheme" parent="@android:style/Theme.Light">
<item name="android:windowBackground">@color/background</item>
</style>
</resources>
and then in your AndroidManifest.xml specify this as the theme for your activities to use.
<activity
android:name=".MyActivity"
android:theme="@style/MyTheme" />
see https://stackoverflow.com/a/10157077/4623782
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With