The accepted answer worked for me using a CollapsingToolbarLayout. It's important to note though, that setSytstemUiVisibility()
overrides any previous calls to that function. So if you're using that function somewhere else for the same view, you need to include the View.SYSTEM_UI_FLAG_LAYOUT_STABLE
and View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
flags, or they will be overridden with the new call.
This was the case for me, and once I added the two flags to the other place I was making a call to setSystemUiVisibility()
, the accepted answer worked perfectly.