Search code examples
androidbackgroundandroid-theme

Make all views transparent to see only theme background image


I saw a lot of modern beautiful apps in the Play Store that use image as background. I decided to use this solution in my application. I develop for minimum API 21 Android 5.0. I prepared image 1920x1080 for xxhdpi Nexus 5 AVD.

enter image description here

I use material light theme. Here is my modified theme definition xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
    <!-- Customize your theme here. -->
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>
    <item name="android:background">@drawable/parquet</item>
    <item name="android:actionBarStyle">@style/transparentActionBar</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="transparentActionBar" parent="android:Widget.Material.Light.ActionBar">
    <item name="android:background">@android:color/transparent</item>
</style>

enter image description here

When I run application I see that each view uses its own scaled copy of theme image. My custom defined style 'transparentActionBar' has no effect on action bar. Only behind status bar I see something like original image. Is it possible to define all views transparency via XML to make visible only screen background image? If no, tell please what is right approach to the solution of this problem.

Regards.


Solution

  • This code does exact what I want

    <resources>
    
    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Material.Light">
        <!-- Customize your theme here. -->
        <item name="android:colorPrimary">@color/colorPrimary</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorAccent</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowBackground">@drawable/parquet</item>
        <item name="android:actionBarStyle">@style/ActionBarStyle.Transparent</item>
    </style>
    <style name="ActionBarStyle.Transparent" parent="android:Widget.Material.Light.ActionBar">
        <item name="android:background">@null</item>
    </style>
    

    enter image description here