最近我遇到了java.lang.IllegalArgumentException: Invalid Transition types
的问题。
这个异常出现在Android API 19上,在我将Android构建工具和支持库更新到版本27后出现。
有人知道KitKat过渡效果发生了什么变化吗?
Fragment fragment = new Fragment();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Transition transition = new AutoTransition();
fragment.setSharedElementEnterTransition(transition);
}
String backStateName = fragment.getClass().getName();
FragmentManager manager = getFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.addSharedElement(view, "TransitionView");
ft.replace(R.id.mainActivity_container, fragment, backStateName);
ft.addToBackStack(backStateName);
ft.commit();
完整异常:
Fatal Exception: java.lang.IllegalArgumentException: Invalid Transition types
at android.support.v4.app.FragmentTransition.chooseImpl(FragmentTransition.java:461)
at android.support.v4.app.FragmentTransition.configureTransitionsOrdered(FragmentTransition.java:3317)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2380)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)
更新
将代码从if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
更改为if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
后,我不再遇到异常。
androidx.*
过渡效果和android.*
过渡效果。 - Adam Johnsimport androidx.transition.TransitionInflater
上缺少了 "x"。 - Sai