In my one activity page, there are many item.
One of items, use startActivity() go to an android system settings activity,
And its activity transition animation is slide_out_left.
The other items use startActivity() go to my own activity.
and activity transition animation is fade_out(defined in my style.xml).
I think that is a reason, but I don't know why?
Why my style.xml changed all activity transition animation except one.
or its there something I didn't notice?
And how can I consistent all activity transition animation in XML file?
(I know overridePendingTransition() can change the animation, but I want to modify in .xml file, not in java code, to stay my java code easy readable in the future.)
Please have a look at this answer and see whether it solves your issue or not: Start Activity with an animation
In short:
<style name="AppTheme">
<item name="android:windowAnimationStyle">#style/MyAnimation</item>
</style>
<style name="MyAnimation" parent="android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">#anim/open_enter</item>
<item name="android:activityOpenExitAnimation">#anim/open_exit</item>
<item name="android:activityCloseEnterAnimation">#anim/close_enter</item>
<item name="android:activityCloseExitAnimation">#anim/close_exit</item>
</style>
If you think this answers your question, please go to that original link that put in the answer and give the original author credit :)
Related
I need to disable Activity transition animation for all the screens in my application. Previous solution worked fine for all Android version:
<style name="base_theme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowAnimationStyle">#null</item>
</style>
... but for Android 8 "Oreo" it cause black screen blinking for every transition (forward or back move). I.e. there is still no any animation, but very annoying blinking take place (90% chance, ~20-30 milliseconds, the whole screen).
According to my "research":
it does not depends on activity content and reproduced with empty activities
there is no any background work which could slow down the transition process
Intent.FLAG_ACTIVITY_NO_ANIMATION blinks as well
overridePendingTransition(0,0) doesn't work too
The only solution I could find:
Define an empty transition animation
<?xml version="1.0" encoding="utf-8"?>
<set />
and apply it to every activity in the application (onCreate & finish)
overridePendingTransition(R.anim.animation_activity_none, R.anim.animation_activity_none);
Question:
Is it some kind of new restrictions for Oreo (i.e. feature), or platform bug, or maybe the application issue?
Are there any other solutions?
[UPDATE]
One more finding. Make sure you call Activity finish() and overridePendingTransition() pair on the main thread! Otherwise thread race happens and overridePendingTransition not applied sometimes.
[UPDATE]
Google has confirmed it's a bug in Android 8.0, presumably fixed in 8.1.
So the "empty animation" fix is for years, until minSdkVersion == 27.
I had the same issue, and I managed to solve it, the idea is to play nothing, please see the xml below:
Values folder
<style name="yourTheme">
<item name="android:windowAnimationStyle">#style/ThemeApp.Animation.Activity.Replace</item>
<style name="ThemeApp.Animation.Activity.Replace">
<item name="android:activityOpenEnterAnimation">#anim/replace_anim</item>
<item name="android:activityOpenExitAnimation">#anim/replace_anim</item>
<item name="android:activityCloseEnterAnimation">#anim/replace_anim</item>
<item name="android:activityCloseExitAnimation">#anim/replace_anim</item>
<item name="android:taskOpenEnterAnimation">#anim/replace_anim</item>
<item name="android:taskOpenExitAnimation">#anim/replace_anim</item>
Anim folder: replace_anim.xml
<set/>
WHAT I HAVE
I have an app with dynamic theming support. Everything works very well, but now while changing the themes I want to give it a fade-in and fade-out effect to make the theme changing transition look seamless.
WHAT I HAV TRIED
1) I have tried to recreate() the activity, but that doesn't apply any animations.
2) I have added a window animations, like this,
<style name="WindowFadeTransition">
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
</style>
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">#android:anim/fade_in</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
And I have applied the style in my activity.
I re-open the activity using,
Intent intent = new Intent(getActivity(), SettingsThemeActivity.class);
getActivity().startActivity(intent);
getActivity().finish();
The animation works really well, but there is a problem.
THE BUG
As I have applied the window animation to the activity itself, whenever I open and close the activity, the animation triggers, which is not what I want. I want the animation to work only when I am changing theme and calling the above lines of code to re-open the activity.
I know it's kind of tricky. How to fix this issue? Any ideas?
Try this After startActivity(); call overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
I have two apps and when i switch from one app to another a black screen is displayed for a while and then the 2nd application starts, can we stop this from happening?
One of the simplest way is to move all the expensive (time-consuming) processing from your activity's onCreate and onStart method to onResume method. By this, your newly launched activity will be visible right after its launched but then will take a little extra to make it available for user to interact. Further, I would suggest you to move all the heavy lifting in AsyncTask for smoother UI experience.
You can also try this theme for your Activity
<resources>
<!-- Base application theme is the default theme. -->
<style name="Theme" parent="android:style/Theme" />
<style name="Theme.MyAppTheme" parent="Theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/my_app_background</item>
</style>
</resources>
If you switching between fragments through screen manager kind of class, which uses enums and fragment transaction to switch between fragments; make sure you put a break statement, after each enum case. This solved my issue. Hope it helps!
I put together a very simple app that uses shared element transitions when starting an activity with Dialog theme (source code on github).
I got the following result:
As you can see there are 2 problems with the transition/animation:
The animation is only visible in the area of the dialog activity so it clips and looks ugly.
There is no transition/animation when I tap outside the activity to
go back.
How can I fix these problems? Any help would be appreciated.
EDIT: After Quanturium's answer I did the following things to get it working:
Use the following theme instead of a Dialog theme:
<style name="AppTheme.Transparent" parent="AppTheme">
<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:backgroundDimEnabled">true</item>
</style>
Use a CardView as the background for Dialog look and for rounded corners and shadows.
Call finishAfterTransition(); when user taps outside the CardView.
Now it looks like this (code), the CardView needs refining to better match the Dialog, but it's working at least.:
An activity transition works like this. When you start your second activity, it is displayed on top of your first one with a transparent background. The shared elements are positioned the same way they are on the first activity and then animated to the correct position specified on the second activity.
In your case you are using android:theme="#style/Theme.AppCompat.Dialog" which mean the size of the second activity's drawing area is smaller than the one from the first activity. This explains the clipping and the no transition when clicking outside.
What you want to do is get rid of that theme, and implement your own layout with a dark background / shadow in order to be able to execute your smooth transition.
I'm trying to get a completely custom Dialog or PopupWindow, without any of the default Android UI controls (title, background, buttons, whatever).
Is this possible at all? I've spent hours searching for this, but no luck... It seems like this should be easily possible, but I can't find it.
Preferably this would be by inflating a View from XML, but at this point anything that would just work would be nice.
Thanks.
Steps I took:
Create a class extending Dialog.
In the onCreate, call setContentView(x, y) with x being your R.layout and y being R.style.popupStyle (see below).
In your res/values/style.xml, you need to override the default DialogWindow style. I tried just making a style that has this one as its parent, but that still didn't clear all defaults. So I checked the Android git tree and got the default style, and just copy-pasted it. This is the one:
<style name="Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowTitleStyle">#android:style/DialogWindowTitle</item>
<item name="android:windowBackground">#android:drawable/panel_background</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:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
You'll get a few errors, just solve them by copying more stuff from the official Android styles.xml and themes.xml files. Here's the contents of my styles.xml file: http://pastebin.com/RRR15YYS
That just gives you a white popup, no borders, nothing. Start customizing. :)
Thanks to mbaird for putting me on the right track.
[edit] I needed to look up my own answer again, and I spent at least ten minutes searching the official android styles/themes files, so here they are, for future reference:
styles.xml and themes.xml.
It sounds like you are trying to really customize an AlertDialog. For what you are wanting to do you may be better off just creating your own class that extends Dialog, similar to how you create activities by writing a class that extends Activity.
You can set the layout XML by calling setContentView() inside the onCreate() method of your custom Dialog class, just like you would in an Activity.
I've run into limitations on how much you can customize AlertDialogs in the past, and I've just implemented my own Dialog classes to get the level of customization that I needed.