Edward
Edward

Reputation: 143

Android Style Background color of all Fragments

I have an app that uses a bottom navigation bar with a nav_host_fragment. I want to set the background color of the nav_host_fragment to have a background color (without changing the color of the bottom navigation bar). I've tried setting the nav_host_fragment background directly and through styles but none of those worked

Here is what I tried (in all possible combinations)

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:background">@color/green</item>
        <item name="android:windowBackground">@color/green</item>
        <item name="android:colorBackground">@color/green</item>
    </style>

Upvotes: 0

Views: 428

Answers (2)

reza laki
reza laki

Reputation: 101

you can do it just by adding android:windowBackground to your themes.xml.
This is my themes.xml:

<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Foody" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">...</item>
    <item name="colorPrimaryVariant">...</item>
    <item name="colorOnPrimary">...</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">...</item>
    <item name="colorSecondaryVariant">...</item>
    <item name="colorOnSecondary">...</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor">...</item>
    <item name="android:windowLightStatusBar" tools:targetApi="m">...</item>

    <!-- YOUR FRAGMENTS AND ACTIVITIES DEFAULT BACKGROUND COLOR -->
    <item name="android:windowBackground">@color/your_target_color</item>
</style>

Upvotes: 0

Gurarshdeep Singh
Gurarshdeep Singh

Reputation: 92

Styles.xml file is used for whole app theme. if you want to show separate color on particular component, change it in declared file

Upvotes: 0

Related Questions