Android - how to set background color of all screens?
A quick and easy way to make sure every activity has the same background color, is to create a theme for your activities to use. That theme would specify the android:windowBackground.
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" />
How to change background color in android app
You need to use the android:background property , eg
android:background="@color/white"
Also you need to add a value for white in the strings.xml
<color name="white">#FFFFFF</color>
Edit : 18th Nov 2012
The first two letters of an 8 letter color code provide the alpha value, if you are using the html 6 letter color notation the color is opaque.
Eg :
How to set background color of a View
You made your button transparent. The first byte is the alpha.
Try v.setBackgroundColor(0xFF00FF00);
How to set background color of an Activity to white programmatically?
Get a handle to the root layout used, then set the background color on that. The root layout is whatever you called setContentView with.
setContentView(R.layout.main);
// Now get a handle to any View contained
// within the main layout you are using
View someView = findViewById(R.id.randomViewInMainLayout);
// Find the root view
View root = someView.getRootView();
// Set the color
root.setBackgroundColor(getResources().getColor(android.R.color.red));
Android find default background color
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
Set background color for the whole app. Android, Jetpack Compose
You can place your app inside a Box
with needed background:
setContent {
YourTheme {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Yellow)
) {
YourApp()
}
}
}
Related Topics
Set Animated .Gif as Background Android
How to Fix Android Studio Getting Stuck Executing Gradle Tasks
Items Inside Gridview Getting Repeated When Screen Scrolls
How to Add Cardview in Layout Xml in Androidx
Can't Grab Progress on Http Post File Upload (Android)
How to Generate The Aac Adts Elementary Stream with Android Mediacodec
Adding a Vertical Scrollbar to an Alertdialog in Android
Custom Attributes in Android Fragments
Android: Tint Using Drawablecompat
Selecting Contact from Autocomplete Textview
How to Get Data from Dialogfragment to a Fragment
Creating Custom Overlay on The Map
View Pager + Imageview +Pinch Zoom + Rotation
How to Change System Navigation Bar Color
Add Drop Shadow Effects to Edittext Field
Convert Image to PDF in Android
Android: How to Programmatically Set Layout_Constraintright_Torightof "Parent"
Supporting Amazon and Android Market (Google Play) Links Inside Application