Transparent Android activity trouble - android

I have an application where the theme can be changed between three different ones. I have two activities that are supposed to have a transparent background and look like a dialog above the previous activity.
I've searched alot for transparent activities here on stack and most of them have the same awnsers. A custom theme with a few properties to enable a transparent background for the activity in question.
The issue for me is that i need to set this custom transparent theme on the parent activity as well to achieve any transparency at all. If i only set a transparent theme on the activity i want to be transparent, it will be a solid background. I've tried everything i could think of but it all boils down to this and im not sure what im doing wrong.
This is my two different parent themes (slimmed down to the neccesary parts):
<style name="StyledActionbar" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:textViewStyle">#style/Iksu.TextView</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="Transparent" parent="Theme.Sherlock.Light.ForceOverflow">
<item name="android:textViewStyle">#style/TextView</item>
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
StyledActionBar is the parent for my three different main themes that is used for all activities that are not supposed to have a transparent background (which is all but two).
Transparent is the parent for three themes that can be used on an activity where the background needs to be transparent.
So the parent activity has a theme based on the StyledActionBar theme. The activity i need to have transparent is based on the Transparent theme.
The background is solid in this state.
If i move:
<item name="android:windowIsTranslucent">true</item>
to StyledActionBar, almost everything works as a charm except a nasty bug in Android 4.4.2 causing the main activity to "fall behind" the OS view when using NavUtils for up-navigation to the main activity.
Any ideas?

in your manigest file
<activity
android:theme="#android:style/Theme.Translucent.NoTitleBar">
</activity>
and in your xml set
android:background="#android/transperent"
also you can use
android:alpha="0.50"

try this one more time :
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
and in the manifest file
<activity android:name=".AlertActivity"
android:theme="#style/Theme.Transparent"/>
Hope it will work for u.

Related

Transparent Background to an android activity class

I am creating an activity and adding views to it dynamically. This activity contains an imageview and a close button. I want the background of the image which is in fact the relative layout background to be transparent so that the icons on the home screen of the device could be visible.
I have tried
Window window = this.getWindow();
window.setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
and also
relativeLayout.setBackgroundColor(Color.parseColor("#00000000"));
and this as well
relativeLayout.setBackgroundColor(0x00000000);
Nothing seems to work. Any pointers will be appreciated. Thanks.
you can create theme and use it for activity
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
<activity android:name=".SampleActivity" android:theme="#style/Theme.Transparent"/>
Define style theme for particular Activity.
In style.xml file
<style name="DialogTheme" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
</style>
And associate this style in Manifest with activity
<activity
android:name="com.pac.activity.YOURACTIVITY"
android:screenOrientation="portrait"
android:theme="#style/DialogTheme" >
</activity>
Hi use this link http://angrytools.com/android/button/. its help for you
Set the
android:background="#android:color/transparent"
Also the colour hexa you are using is wrong...
00000000 is hexa for non transparent white
Use
Ff000000 instead
In the top most viewgroup you have. This will essentially create a background with transparent colour on which other views will lie.
You can adjust transparency using other colours in that place.

Making android:windowBackground as #null by overriding the theme makes the view to repeat

I recently moved one of my activities(starting with a blank activity in Android Studio) to a full screen activity. Earlier, my activity looked like this.
I have few custom views inside my layout. To make my activity full screen, I just created a new full screen activity using the option in Android Studio and copied my code to the new activity. I noticed that the newly created full screen activity generated a theme overriding the application theme and then assigns this theme to the activity. The generated theme is as follows:
<style name="FullscreenTheme" parent="MyDefaultTheme">
<item name="android:actionBarStyle">#style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">#null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/black_overlay</item>
</style>
The problem I face is that the item
<item name="android:windowBackground">#null</item>
causes the activity view to be rendered like this:
If I comment that line in the new theme (or give it a color), everything seems to be working fine. I read few articles like this to understand this but I am still not clear what is happening in my case. Any explanations for this issue?
Also, I do not see any utility of
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="android:background">#color/colorBackgroundLT</item>
</style>
Can anybody explain this as well?

Android Activity transparent background

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.
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.
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.

How to get Transparent android activity over the lockscreen?

I want my activity to show up on lockscreen(which is working fine). but i want to get that activity transparent..
I tried 2 methods both are not allowing my activity to show on lockscreen.
Method 1
android:theme="#android:style/Theme.Translucent.NoTitleBar"
Method 2
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Both are not allowing to show the activity on lockscreen.
Is there any method you know?
Try setting following codes in your activity.I have not tried it, it may work.
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
This is because you defined windowIsFloating to be true. An activity won't show in front of a lockscreen if the width or height are modified, or if it is set to be floating.
You should set windowIsFloating to false, windowBackground to transparent and if you would still like the dialog-effect, create a dialogfragment, and show that in your onCreate of the activity. And of course, remove the ActionBar from the activity:
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>

White background during app launch

I want to get rid of the white color during the short period when my app is launching but the content isn't displayed, yet.
My main activity is using a style (from the Manifest) that extends #style/Theme.Sherlock.Light.DarkActionBar with the background set to <item name="android:background">#android:color/transparent</item>. Nowhere in my layout do I use a white background color, yet it appears for a brief moment during app launch.
In the HierarchyViewer I exported the layers and checked back that there is really no white solid in the layout hierarchy.
What setting controls the background color before the layout is drawn? Thanks.
There's another background attribute in your theme - windowBackground, and you implicitly set it to white by inheriting your style from #style/Theme.Sherlock.Light.DarkActionBar (notice the .Light. part in the name).
You can either use dark version of theme or set it explicitly by including windowBackground in your style definition:
<item name="android:windowBackground">#color/your_color</item>
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
Or you can use drawable. I created a theme for my spash screen like as below :)
<style name="SceneTheme.Light.NoActionBar" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="SceneTheme.Light.NoActionBar.Transparent.StatusBar" parent="SceneTheme.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowBackground">#drawable/bg_splash</item>
</style>

Categories

Resources