1

I've tried on Nougat and Oreo. Both phones are stock android and both views are visible and on screen. I require these views for my sharedElementTransition. This question has been asked before here but with no answer. This is happening to a lot of people and they discuss it here in the comments of Alex Lockwood's answer, but with no definite solution.

I am calling findViewById() from my activity and have tried both

findViewById(android.R.id.statusBarBackground);

and

getWindow().getDecorView().findViewById(android.R.id.statusBarBackground);

I've called the findViewById() after setContentView()

Possibly related, but unlike progressBar, statusBar and navigationBar views do exist almost all the time.

Code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        getWindow().setSharedElementEnterTransition(getTransitionSet());
        getWindow().setSharedElementExitTransition(getTransitionSet());
        getWindow().setSharedElementReturnTransition(getTransitionSet());
        getWindow().setSharedElementReenterTransition(getTransitionSet());
        ActivityCompat.postponeEnterTransition(this);
        setEnterSharedElementCallback(mCallback);
    }
    setContentView(R.layout.summary_image_preview);
    navigationBar = getWindow().getDecorView().findViewById(android.R.id.navigationBarBackground);
    statusBar = getWindow().getDecorView().findViewById(android.R.id.statusBarBackground);
    mToolbar = (Toolbar) findViewById(R.id.toolBar);
    // etc...

}

Toolbar is a normal view inside my content view and it works fine. but statusBar and navigationBar are null

ColonD
  • 954
  • 10
  • 28
  • 1
    Can you please post more of the code, so we can analyse it and try to locate the error? It's hard to tell you what the problem might be without looking at the code. – deluxe1 Mar 28 '18 at 12:50
  • Updated with code. There's not much to It other than what I've said. – ColonD Mar 28 '18 at 12:56

1 Answers1

0

The Views return null in onCreate() function. I checked the same Views inside my Fragment's onViewCreated() and they were not null. I fixed the issue by delaying findViewById() until the point where I needed it.

For some reasor, while other views are available in onCreate(), the Views outside your application are only accessible after Fragment View creation

ColonD
  • 954
  • 10
  • 28