How to make a transparent activity using AppCompat - android

I have 2 activity 1 is main and other is for showing an image over all other activities My main activity is using this theme
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowIsTranslucent">true</item>
</style>
and My Image activity is using this theme
<style name="Theme.AppCompat.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
thing is its showing exactly what i wan on some devices showing the background of other activity but in some devices its showing the background of homescreen
this is where its showing background of home screen
this is where its showing my activity background
I am stuck with this problem for quite few long any help will be greatly appreciated.

If you use Toolbar or a custom toolbar, try set color background to transparent (#00000000). It works fine with me. Good luck!

Related

How to make a status bar transparent in a dialog fragment?

I want to make my status bar and navigation bar transparent (not translucent).
<style name="FullScreenDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#null</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:background">#null</item>
</style>
I have tried a number of different combinations but none seem to work. This current setup gives me a black status bar background. I'm sure I'm missing something simple. I have also tried using:
android:fitsSystemWindows="true"
On my layouts.
Thank you for the help.

How to make an activity background completely transparent (not translucent)?

In my android activity, I need to make the background of the activity transparent. For that, I found solutions online saying to do this in theme.
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
However this makes the activity background translucent i.e it isn't perfectly transparent, it is slightly grey. Is there a way to get a perfectly transparent background such that the screen below it is perfectly viisible. Thanks!
Try this
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#color/transparent</item>
Try this
<style name="TransparentTheme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Usage
<activity
android:name=".activity"
android:theme="#style/TransparentTheme.Base" />

style.xml android:windowIsTranslucent dialogs not showing

I have created a transparent AppCompatActivity that is a type of 'launcher' activity for other activities. This launcher activity uses a transparent style as found with other stackoverflow questions.
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.Light.NoActionBar">
<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>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/primary</item>
</style>
Sometimes this launcher activity needs to show a progress dialog. However, the progress dialog does not show up when I use the tag android:windowIsTranslucent. Commenting out this tag allows the progress dialog to appear, but the activity is no longer transparent.
Is there some sort of alternative solution for this?
I didn't tried this solution, But i think this could work.
Just add <item name="android:windowIsTranslucent">false</item> in your AppCompatAlertDialogStyle
Solution would be like
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.Light.NoActionBar">
<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>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#color/primary</item>
<item name="android:windowIsTranslucent">false</item>
</style>

Styling of AlertDialog buttons

In my application I use holoeverywhere. I would like to change the appearance of AlertDialog and I got stuck on buttons below alert dialog. I took a look how things were done in holoeverywhere and I tried to modify that.
Here is backtracking of my reasoning:
In theme there are atributes which define alertDialogTheme and some other stuff. We will come back later to selectableItemBackground also.
<style name="Holo.Base.Theme" parent="Theme.AppCompat">
...
<item name="alertDialogTheme">#style/Holo.Theme.Dialog.Alert</item>
...
<item name="buttonBarButtonStyle">?borderlessButtonStyle</item>
...
<item name="selectableItemBackground">#drawable/item_background_holo_dark</item> *
...
</sytle>
So i figure alertDialogStyle is my target which is further defined in styles:
<style name="Holo.Base.Theme.Dialog" parent="Holo.Theme">
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowAnimationStyle">#style/Holo.Animation.Dialog</item>
<item name="android:windowBackground">#drawable/dialog_full_holo_dark</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowTitleStyle">#style/Holo.DialogWindowTitle</item>
<item name="borderlessButtonStyle">#style/Holo.Button.Borderless.Small</item>
<item name="buttonBarStyle">#style/Holo.ButtonBar.AlertDialog</item>
<item name="listPreferredItemPaddingLeft">16dip</item>
<item name="listPreferredItemPaddingRight">16dip</item>
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<item name="windowAnimationStyle">#style/Holo.Animation.Dialog</item>
<item name="windowContentOverlay">#null</item>
<item name="windowMinWidthMajor">#dimen/dialog_min_width_major</item>
<item name="windowMinWidthMinor">#dimen/dialog_min_width_minor</item>
<item name="windowNoTitle">true</item>
</style>
<style name="Holo.Theme.Dialog" parent="Holo.Base.Theme.Dialog" >
</style>
<style name="Holo.Theme.Dialog.Alert" parent="Holo.Theme.Dialog">
<item name="alertDialogStyle">#style/Holo.AlertDialog</item>
<item name="alertDialogTitleDividerColor">#color/holo_blue_light</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
<style name="Holo.Button.Borderless" parent="Holo.Button">
<item name="android:background">?selectableItemBackground</item>
<item name="android:paddingLeft">4dip</item>
<item name="android:paddingRight">4dip</item>
</style>
So Holo.Theme.Dialog.Alert is inherited from Holo:base.Theme.Dialog which has an atribute for borderlessButtonStyle, which I guess defines the buttons of alert dialog.
Style Holo.Button.Borderless referes the atribute selectableItemBackground for its background. Atribute is set in application theme itself. So, my reasoning is if I inherit from theme Holo.theme and set selectableBackground atribut my change should reflect in customized alert dialog buttons and everything else where this background is used.
<style name="ThemeCustom" parent="#style/Holo.Theme>
…
<item name="selectableItemBackground">#drawable/custom_item_background </item>
…
</style>
But this does not work. No change is visible in alert dialog buttons. Is there something wrong with my reasoning?

Applying Styles Android

I want to make my Activity appear like a Dialog box, but without the title bar. So I think I should write this style myself.
But how should this XML style be?
I already tried the Theme.Dialog for my Activity, but the thing is, I don't want the background of the Theme.Dialog style. And without an label for screen.
I has all the screen build by XML, I want just center it on screen and has a semi-transparent outside background.
Just do this
<activity android:name=".MyActivity"
android:theme="#style/CustomTheme"
android:label="Gana"/>
res/values/styles.xml
<resources>
<style name="CustomTheme" parent="android:Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/mybackground</item>
<item name="android:gravity">center</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
If you don't want background remove that.

Categories

Resources