Say I have a menu sliding out in android and I want to darken whatever was behind it.
I tied making a full screen layout and use a countdown timer to make its background gradually go from transparent to 50% black, but it gets slow as hell.
Are there any other options to make a gradual transition? Other then making it in a snap?
Thanks!
Why don't you use a theme? Under res/values, make a styles.xml file. In that, define
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Translucent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#color/cache_color</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
</resources>
Then in your manifest:
<activity android:name="com.example.FooActivity" android:theme="#style/Theme.Translucent"></activity>
Related
I have a specifix view that needs to use windowIsTranslucent = true. This generates some problems that I'm having hard time to understand... the specific one that I'm trying to resolve now is why the transition in/out changes to slide up / down only because of this style.
I want to use windowIsTranslucent = true but with the standard activity transition animation.
These are relevant styles
<style name="AppTheme.AppCompat.Translucent" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/opacity_background</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#07819A</item>
<item name="android:actionMenuTextColor">#color/White</item>
<item name="android:windowDisablePreview">true</item>
<item name="colorPrimary">#07819A</item>
<item name="colorPrimaryDark">#006471</item>
<item name="android:fastScrollTextColor">#ffffff</item>
<item name="android:dropDownListViewStyle">#style/FilterSpinnerStyle</item>
<item name="android:actionOverflowButtonStyle">#style/AppTheme.OverFlow</item>
<item name="android:autofilledHighlight">#android:color/transparent</item>
</style>
What I have tried witout success:
Added this line to AppTheme.AppCompat.Translucent
<item name="android:windowAnimationStyle">#+android:style/Animation.Translucent</item>
Added this line to AppTheme.AppCompat.Translucent
<item name="android:windowAnimationStyle">#+android:style/Animation.Activity</item>
Used CurrentActivity.OverridePendingTransition(someId, someId); and it works. The problem is that animation is a little laggy when I try to mimic standard animation and I also have the problem to use the correct animation for each version of Android.
I tried some other things that I don't have at the top of my head right now... the thing is that nothing seems to be enough :(
You can override the default transition animation for your app by declaring a custom style with your desired animations like this:
<style name="CustomAnimation" parent="#android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">#anim/your_desired_animation</item>
<item name="android:activityOpenExitAnimation">#anim/your_desired_animation</item>
<item name="android:activityCloseEnterAnimation">#anim/your_desired_animation</item>
<item name="android:activityCloseExitAnimation">#anim/your_desired_animation</item>
</style>
And then by setting it to your base theme you can set the custom transition animation for your app
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">
<!-- Customize your theme here. -->
...
<item name="android:windowAnimationStyle">#style/CustomAnimation</item>
</style>
Thus you can declare your own transition animations. Even if the standard animations not working, you can always make your own like the standard one.
I have created a simple image using Inkscape with a transparent background, alpha(0) and at the center, I have a small logo. I then applied it to my styles like below:
<style name="SplashScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#drawable/splashscreen</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/loginHeaderBackground</item>
</style>
It works fine, however, I'm missing my main objective, its displaying a black screen with the middle icon instead of a transparent one.
What I want (User should be able to still see their phone background when the app starts to launch)
What I'm getting
Why is this?
There is an example for you. I wrote custom theme and i added this theme to my activty. You should add this your splash activity in manifest file.
<activity ...
android:theme="#android:style/Theme.TranslucentTheme"
.../>
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TranslucentTheme" parent="android:Theme.Translucent">
<item name="android:windowBackground">#color/transparent_black</item>
</style>
<color name="transparent_black">#DA000000</color>
</resources>
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.
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.
How can I change the color of the semi-transparent background that is shown behind a Dialog.
The default is black and I want to make it white (with the same alpha like the default)
This is the theme I'm using for my custom dialog:
another question - how can I make the dialog to fill the screen width (with 20dp margin on each side)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomDialogTheme" parent="android:Theme.Dialog">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:padding">30dp</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:background">#color/white</item>
</style>
</resources>
Make a xml layout and set the layout to the dialog.
This might help for the syntax: you must set the content of the dialog to a layout
http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application
This might help for the background: you must overwrite the theme/style
Android Custom PopupWindow/Dialog