如何将另一个 activity 的名称作为参数传递给另一个 activity 中的方法
How to pass name of another activity as a parameter to a method in another activity
所以我想在这里使用 ActivityOptionsCompat
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeViewer.class,
v, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
第一个参数应该是一个 Activity 对象,我试图通过相关的 class 文件提供它,但我得到以下类型转换错误 -
Error:(194, 54) error: no suitable method found for makeSceneTransitionAnimation(Class<NoticeViewer>,View,String)
method ActivityOptionsCompat.makeSceneTransitionAnimation(Activity,View,String) is not applicable
(actual argument Class<NoticeViewer> cannot be converted to Activity by method invocation conversion)
method ActivityOptionsCompat.makeSceneTransitionAnimation(Activity,Pair<View,String>...) is not applicable
(actual argument Class<NoticeViewer> cannot be converted to Activity by method invocation conversion)
我漏掉了一些非常简单的东西,那是什么?
使用 NoticeViewer.this
而不是 NoticeViewer.class
将当前 Activity 上下文作为第一个参数传递:
ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeBoard.this,...)
所以我想在这里使用 ActivityOptionsCompat
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeViewer.class,
v, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
第一个参数应该是一个 Activity 对象,我试图通过相关的 class 文件提供它,但我得到以下类型转换错误 -
Error:(194, 54) error: no suitable method found for makeSceneTransitionAnimation(Class<NoticeViewer>,View,String)
method ActivityOptionsCompat.makeSceneTransitionAnimation(Activity,View,String) is not applicable
(actual argument Class<NoticeViewer> cannot be converted to Activity by method invocation conversion)
method ActivityOptionsCompat.makeSceneTransitionAnimation(Activity,Pair<View,String>...) is not applicable
(actual argument Class<NoticeViewer> cannot be converted to Activity by method invocation conversion)
我漏掉了一些非常简单的东西,那是什么?
使用 NoticeViewer.this
而不是 NoticeViewer.class
将当前 Activity 上下文作为第一个参数传递:
ActivityOptionsCompat.makeSceneTransitionAnimation(NoticeBoard.this,...)