I am developing a reading app from where users can read multiple types of documents.
This app also has a feature to enable full screen by touching any part of the screen. I am able to enable/disable full screen by hiding the status bar and the tool bar (ActionBar) with the following line of codes:
if (toolbar.getVisibility() == View.VISIBLE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
appbar.animate().translationY(-112).setDuration(600L)
.withEndAction(new Runnable() {
@Override
public void run() {
toolbar.setVisibility(View.GONE);
}
}).start();
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
toolbar.setVisibility(View.VISIBLE);
appbar.animate().translationY(0).setDuration(600L).start();
}
But the real issue is when I enable full screen the content moves upwards and when disable it moves downwards.
I don't want to move my content. I have seen in Google doc app that content does not move while enabling/disabling full screen.
Using RelativeLayout instead of CoordinatorLayout as a root layout I can avoid toolbar pushes the content but it pushes a little bit when I hide the status bar.
Please help.
Now your issue is that the status bar pushes the activity content down when it's shown.
So, to solve this you can make the status bar overlapping with the activity window by adding the below to the activity's
onCreate()methodUPDATE
To support APIs below Kitkat try to create a style.xml file for (v-19) qualifier, and add the below attributes
UPDATE: using custom ActionBar
Layout:
Behavior
Use
NoActionBartheme int style.xmlOverride style.xml (v.19)
Preview