Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

android - How to use standard enter / exit animation transition for activities when using windowIsTranslucent in true?

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 :(

question from:https://stackoverflow.com/questions/65845278/how-to-use-standard-enter-exit-animation-transition-for-activities-when-using

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...