MockApp. Mastering Full Screen Activities

Alexey Zhuravlev
mock-app
Published in
2 min readMay 23, 2019

In this article we learn how to make full-screen activities taking into account height of the status and navigation bars.

Basically, we can get a full-screen Activity in Android using following code:

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
...
super.onCreate(savedInstanceState);
...
}

And use View.setFitsSystemWindow(true|false) to control whether our view will be placed below status bar or above navigation bar.

If View.setFitsSystemWindow(true) then system just add padding to the View to reflect height of the status bar and navigation bar.

This is done in View.java

private boolean fitSystemWindowsInt(Rect insets) {
if ((mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS) {
...
internalSetPadding(localInsets.left, localInsets.top, localInsets.right, localInsets.bottom);
...

But sometimes we want to add only top padding (status bar) or only bottom padding (navigation bar) to our View.

To achieve this we could override View.onApplyWindowInsets method or set listener View.setOnApplyWindowInsetsListener to take control over default implementation.

Now lets take a look how easily you could control full-screen Activities and Views using MockApp.

Take a look at the picture

Property Full Screen on the Root element determine if the Activity will be full screen or not.

Properties Fits Status Bar and Fits Nav Bars are responsible on top and bottom padding of the individual view.

As well you can change Status Bar and Navigation Bar background color modifying corresponding properties of the Root element.

That’s it!

Next lets see what layouts we could get playing with that.

Sample project you could get from here.

Layout1
Layout2
Layout3
Layout4

Thanks for reading! Your feedback is great!

Sample project you could get from here.

MockApp application is here.

--

--