Why the XML specified transition isn't executed? (or why its specified duration isn't taken account?)
Asked Answered
D

1

2

I followed this documentation: https://developer.android.com/training/transitions/start-activity#java .

First, I will show you my implementation. You will find my question at the end of this post.

Thus, I modified 4 files:

  1. fade.xml, which defines the duration of the fade in transition.
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
    <fade android:fadingMode="fade_in" android:duration="3000" />
</transitionSet>
  1. values/styles.xml, which defines the windowEnterTransition thanks to fade.xml. Note that MainActivity's parent, AppTheme, has Material as parent.

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:windowActivityTransitions">true</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="MainActivityTheme" parent="AppTheme">
    <item name="android:windowEnterTransition">@transition/fade</item>
</style>

  1. Since I created this new theme "MainActivityTheme", I also modified the Android Manifest to specify this new theme to this activity:
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:theme="@style/MainActivityTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
  1. Finally, I have set the enter transition in MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setEnterTransition(new Fade(Fade.IN));
    setContentView(R.layout.activity_main);
}

Emulator and Gradle build

build.gradle (Module: app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.."
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Emulator

The version of Android installed within the emulator is: 5.1.1 (cf. "About phone" in the settings of Android, in the emulator).

Question

However, when I launch my application, the main activity's UI doesn't fade in. Do you know why ? In other words: Why the XML specified transition isn't executed? (or why its specified duration isn't taken account?)

I also tried to move <item name="android:windowActivityTransitions">true</item> from the theme MainActivityTheme (file: styles.xml) to the theme AppTheme (file: the same, i.e.: styles.xml). But it didn't fix this bug.

Disafforest answered 8/9, 2018 at 16:40 Comment(4)
which device u testedAutotype
I just use an emulatorDisafforest
emulator os like kitkat?Autotype
Nope, Android 5.5.1 so it should work!Disafforest
A
0

Try This I hope its Work

Activity transitions in material design apps provide visual connections between different states through motion and transformations between common elements. You can specify custom animations for enter and exit transitions and for transitions of shared elements between activities.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    setContentView(R.layout.activity_main);
}

Also Read This Question This May helps You WindowEnterTransition Not Affecting Activity Transition

Autotype answered 8/9, 2018 at 17:14 Comment(11)
requestFeature(...TRANSITIONS) must be used only if <item name="android:windowActivityTransitions">true</item> isn't written - note that I still have tested and it didn't fix the bugDisafforest
@Disafforest did u applied parent theme of apptheme like parent="android:Theme.MaterialAutotype
Yes: <style name="AppTheme" parent="android:Theme.Material"> and <style name="MainActivityTheme" parent="AppTheme">Disafforest
But when user launches my app, it's from an activity no? (an activity of some Android OS process, or another application's activity) So it should work.Disafforest
this animation works only when u start activity between activityAutotype
Yes, I understood what you have written in your precedent message. But if the user launches my application (main activity) from another application (its activity) or from some Android OS process' activity, thus in these cases there is indeed two activities (mine and the other). So this transition between these both activities should be executed no?Disafforest
It's a splashscreen but with an animation!Disafforest
But if the user launches my application (main activity) from another application (its activity) > if this appliacation implements overridePendingTransition(R.anim.fade_in, R.anim.fade_out); its should workAutotype
Hum, ok. So in résumé, my solution has great chances to not work. I will do my animated splashscreen following this answer: #52234957Disafforest
It's not ahah, but I have to re-read my code. Thanks for provided help!Disafforest
@Disafforest :) most welcomdAutotype

© 2022 - 2024 — McMap. All rights reserved.