2017-05-08 11 views
2

私はこのコードの共有要素の移行を定義しています:共有要素変色して、ステータスとアクションバーの重複要素

Intent myIntent = new Intent(getActivity(), DetailActivity.class); 
      myIntent.putExtra("url", url); 
      myIntent.putExtra("preview_url", preview_url); 
      // Define the view that the animation will start from 
      View viewStart = view.findViewById(R.id.grid_item_image); 
      Pair<View, String> p4 = Pair.create(viewStart, "wallpaper_transition"); 


      ActivityOptionsCompat options = 
        ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),p4); 
      ActivityCompat.startActivity(getActivity(), myIntent, options.toBundle()); 

そして、それは正常に動作しますが、時には移行要素はアクションバーが重複する不具合がありますそして、次のようにステータスバーには、私は、コードを編集した:

Intent myIntent = new Intent(getActivity(), DetailActivity.class); 
      myIntent.putExtra("url", url); 
      myIntent.putExtra("preview_url", preview_url); 
      // Define the view that the animation will start from 
      View viewStart = view.findViewById(R.id.grid_item_image); 
      View decor = getActivity().getWindow().getDecorView(); 
      //these appear to be null 
      View statusBar = decor.findViewById(android.R.id.statusBarBackground); 
      View navBar = decor.findViewById(android.R.id.navigationBarBackground); 
      View actionBar = decor.findViewById(R.id.action_bar_container); 

      Pair<View, String> p1 = Pair.create(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME); 
      Pair<View, String> p2 = Pair.create(navBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME); 
      Pair<View, String> p3 = Pair.create(actionBar, "actionbar"); 
      Pair<View, String> p4 = Pair.create(viewStart, "wallpaper_transition"); 


      ActivityOptionsCompat options = 
        ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), 
          p1, 
          p2, 
          p3, 
          p4); 
      ActivityCompat.startActivity(getActivity(), myIntent, options.toBundle()); 

をしかしstatusBaractionBarnavBarnullをしているので、今、私はクラッシュを取得します。

java.lang.IllegalArgumentException: Shared element must not be null 
                    at android.app.ActivityOptions.makeSceneTransitionAnimation(ActivityOptions.java:561) 
                    at android.support.v4.app.ActivityOptionsCompat23.makeSceneTransitionAnimation(ActivityOptionsCompat23.java:71) 
                    at android.support.v4.app.ActivityOptionsCompat.makeSceneTransitionAnimation(ActivityOptionsCompat.java:263) 
                    at com.dcs.wallhouse.ListFragment$WallHolder.onClick(ListFragment.java:185) 
                    at android.view.View.performClick(View.java:5198) 
                    at android.view.View$PerformClick.run(View.java:21147) 
                    at android.os.Handler.handleCallback(Handler.java:739) 
                    at android.os.Handler.dispatchMessage(Handler.java:95) 
                    at android.os.Looper.loop(Looper.java:148) 
                    at android.app.ActivityThread.main(ActivityThread.java:5417) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
+0

あなたがfindviewbyidたときにステータスバー、アクションバーとナビゲーションバーがnullでないことをデバッグにチェックインしましたか? – motis10

+0

私が質問したように、それらのすべてはnullです。 – user11230

答えて

0

これらのビューは次のように直接取得しようとしてください:

View statusBar = getActivity().findViewById(android.R.id.statusBarBackground); 
    View navigationBar = getActivity().findViewById(android.R.id.navigationBarBackground); 
関連する問題