-1

I have a pretty common requirement.

I have an Activity that needs to appear Full-screen on Mobile Devices (Size-Normal), and as a Dialog on Tablet Devices(Size-Large and Size-XLarge).

In both the formats, I have UI-Widgets displayed in the content-view of the Activity such as a Horizontal-ProgressBar, Circular-ProgressBar as a load-indicator etc, which need to follow a consistent Material-Design with Custom-Branded colors etc. I cannot forgo this requirement.

I have defined custom-styles based on default Android Themes and Styles, and use them across the App for all Activities. Following are the custom-themes.

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:colorPrimary" tools:ignore="NewApi">
        @color/light_black
    </item>
    <item name="colorPrimary">@color/light_black</item>
    <item name="android:colorAccent" tools:ignore="NewApi">@color/sapphire</item>
    <item name="colorAccent">@color/sapphire</item>
    <item name="android:colorBackground">@color/primary_background</item>
    <item name="android:textColorPrimary">@color/title_color</item>
    <item name="android:colorButtonNormal" tools:ignore="NewApi">@color/sapphire</item>
    <item name="colorButtonNormal">@color/sapphire</item>
    <item name="android:colorForeground" tools:ignore="NewApi">
        @color/title_color
    </item>
    <item name="android:titleTextStyle">@style/toolbar_title</item>
    <item name="android:navigationIcon" tools:ignore="NewApi">?android:attr/homeAsUpIndicator</item>
    <item name="navigationIcon">?android:attr/homeAsUpIndicator</item>
    <item name="android:colorControlNormal" tools:ignore="NewApi">@color/white</item>
    <item name="colorControlNormal">@color/white</item>
</style>

<style name="AppTheme.Light" parent="AppTheme">
    <item name="android:windowBackground">@color/white</item>
</style>

<style name="AppTheme.Dialog" parent="AppTheme.Light">
    <item name="android:windowBackgroundFallback" tools:ignore="NewApi">
        @android:color/transparent</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundFloating" tools:ignore="NewApi">
        @android:color/transparent</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionBarOverlay">false</item>
    <item name="windowActionModeOverlay">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowClipToOutline" tools:ignore="NewApi">false</item>
    <item name="android:windowTitleStyle">@null</item>
    <item name="android:windowTitleBackgroundStyle">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
    <item name="android:windowEnableSplitTouch">true</item>
    <item name="android:fitsSystemWindows">true</item>
    <item name="android:fillViewport">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:backgroundDimAmount">0.2</item>
</style>

I use the AppTheme as the default theme across all Activities in the App, and AppTheme.Dialog for the specific Activity described above only for Tablet Devices. The Activity does appear as a Floating-Dialog window centered in the Tablet Screen, dismisses when touched outside like a typical Dialog, everything is good, but the problem is that the Activity's window-background is like pitch-ink-black.

My requirement is that the Activity as a Floating-Dialog in Tablet Devices should have a Transparent Background showcasing the previous activity window-content possibly dimmed and darkened.

How do I achieve this, without having to use Theme.Dialog or Theme.Translucent, as I said before, I need the Material-Design specs for the UI-Widgets not to change from the original "AppTheme" style.

I also will need to re-use a lot of custom private methods declared in the Activity class, so loading the content-view layout-file into a Dialog instance is most definitely not preferred.

Oh, btw, compileSdkVersion is latest at 24, minSdkVersion is 16 and targetSdkVersion is 24, buildToolsVersion is also latest at 24.0.1, but that's a different concern altogether.

AndroidRocks
  • 292
  • 4
  • 16

2 Answers2

0

If you are using Fragments, then remember not to replace the new fragment but add it on top of the previous one and define the theme with background color as transparent.

If you are using activities, just use transparent themed background for the activity or dialog whichever you are using.

Hitesh
  • 331
  • 2
  • 10
  • I am not using Fragments. Fragments are a bad design, they are post-processed, which means the Fragment Life-cycle executes after the Activity's life-cycle and the Activity's content-view draw-cycle completes. As for the transparent themed background, as I had mentioned previously, I have other UI-Widgets that strictly need to follow the specified Material-Design style guidelines, such as a Horizontal Progress-Bar which is apparently different in appearance between Theme.AppCompat.NoActionBar, Theme.Dialog and Theme.Translucent. – AndroidRocks Jul 28 '16 at 13:16
0

So, I finally figured. I had declared "AppTheme.Light" as the default-theme in the Android Manifest for the same Activity since it was supposed to appear full-screen with a White-Opaque background in Mobile Devices, while the same Activity was supposed to appear as a Floating-Dialog in Tablet Devices, so I was setting the Theme 'Programmatically' to AppTheme.Dialog within the Activity's life-cycle.

I should be doing the same in reverse. I should declare the applicable theme in the Android Manifest file for Tablet Devices, and rewrite all of those Floating-Dialog properties to a Full-Screen layout-mode when the Device screen-size is Normal or Small.

AndroidRocks
  • 292
  • 4
  • 16