Draw content under both status bar and navbar while maintaining fitsSystemWindows=“true” behaviour











up vote
0
down vote

favorite












I'm trying to draw content under both status bar and navigation bar with them being completely transparent while also taking advantage of fitsSystemWindows="true".



For the status bar, fitsSystemWindows="true" along with the following code works fine.



getWindow() .getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);


enter image description here



However, when I add the following line to draw content under the navigation bar, the insets that we get from fitsSystemWindows="true" are no longer available.



getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);


enter image description here



Some solutions include obtaining the statusbar and navigation bar heights like so



getResources().getDimensionPixelSize(getResources().getIdentifier("status_bar_height", "dimen", "android"));


and using it as padding.



However, this method is discouraged.



Is there any way to maintain the behaviour of fitsSystemWindows="true" while drawing content under both the status bar and the navigation bar? Thanks in advance.










share|improve this question
























  • Can you just draw an illustration so that it can be clear
    – Sai Jayant
    Nov 19 at 9:21










  • @SaiJayant I have included screenshots. As you can see, in the first screenshot, the AppBar and the rest of the content is properly laid out with the appropriate insets provided by fitsSystemWindows="true". In the second secreenshot, the insets disappear. Thanks for your time.
    – DavidH
    Nov 19 at 9:36















up vote
0
down vote

favorite












I'm trying to draw content under both status bar and navigation bar with them being completely transparent while also taking advantage of fitsSystemWindows="true".



For the status bar, fitsSystemWindows="true" along with the following code works fine.



getWindow() .getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);


enter image description here



However, when I add the following line to draw content under the navigation bar, the insets that we get from fitsSystemWindows="true" are no longer available.



getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);


enter image description here



Some solutions include obtaining the statusbar and navigation bar heights like so



getResources().getDimensionPixelSize(getResources().getIdentifier("status_bar_height", "dimen", "android"));


and using it as padding.



However, this method is discouraged.



Is there any way to maintain the behaviour of fitsSystemWindows="true" while drawing content under both the status bar and the navigation bar? Thanks in advance.










share|improve this question
























  • Can you just draw an illustration so that it can be clear
    – Sai Jayant
    Nov 19 at 9:21










  • @SaiJayant I have included screenshots. As you can see, in the first screenshot, the AppBar and the rest of the content is properly laid out with the appropriate insets provided by fitsSystemWindows="true". In the second secreenshot, the insets disappear. Thanks for your time.
    – DavidH
    Nov 19 at 9:36













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to draw content under both status bar and navigation bar with them being completely transparent while also taking advantage of fitsSystemWindows="true".



For the status bar, fitsSystemWindows="true" along with the following code works fine.



getWindow() .getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);


enter image description here



However, when I add the following line to draw content under the navigation bar, the insets that we get from fitsSystemWindows="true" are no longer available.



getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);


enter image description here



Some solutions include obtaining the statusbar and navigation bar heights like so



getResources().getDimensionPixelSize(getResources().getIdentifier("status_bar_height", "dimen", "android"));


and using it as padding.



However, this method is discouraged.



Is there any way to maintain the behaviour of fitsSystemWindows="true" while drawing content under both the status bar and the navigation bar? Thanks in advance.










share|improve this question















I'm trying to draw content under both status bar and navigation bar with them being completely transparent while also taking advantage of fitsSystemWindows="true".



For the status bar, fitsSystemWindows="true" along with the following code works fine.



getWindow() .getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().setStatusBarColor(Color.TRANSPARENT);


enter image description here



However, when I add the following line to draw content under the navigation bar, the insets that we get from fitsSystemWindows="true" are no longer available.



getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);


enter image description here



Some solutions include obtaining the statusbar and navigation bar heights like so



getResources().getDimensionPixelSize(getResources().getIdentifier("status_bar_height", "dimen", "android"));


and using it as padding.



However, this method is discouraged.



Is there any way to maintain the behaviour of fitsSystemWindows="true" while drawing content under both the status bar and the navigation bar? Thanks in advance.







android android-layout






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 9:41

























asked Nov 19 at 8:40









DavidH

1,5631025




1,5631025












  • Can you just draw an illustration so that it can be clear
    – Sai Jayant
    Nov 19 at 9:21










  • @SaiJayant I have included screenshots. As you can see, in the first screenshot, the AppBar and the rest of the content is properly laid out with the appropriate insets provided by fitsSystemWindows="true". In the second secreenshot, the insets disappear. Thanks for your time.
    – DavidH
    Nov 19 at 9:36


















  • Can you just draw an illustration so that it can be clear
    – Sai Jayant
    Nov 19 at 9:21










  • @SaiJayant I have included screenshots. As you can see, in the first screenshot, the AppBar and the rest of the content is properly laid out with the appropriate insets provided by fitsSystemWindows="true". In the second secreenshot, the insets disappear. Thanks for your time.
    – DavidH
    Nov 19 at 9:36
















Can you just draw an illustration so that it can be clear
– Sai Jayant
Nov 19 at 9:21




Can you just draw an illustration so that it can be clear
– Sai Jayant
Nov 19 at 9:21












@SaiJayant I have included screenshots. As you can see, in the first screenshot, the AppBar and the rest of the content is properly laid out with the appropriate insets provided by fitsSystemWindows="true". In the second secreenshot, the insets disappear. Thanks for your time.
– DavidH
Nov 19 at 9:36




@SaiJayant I have included screenshots. As you can see, in the first screenshot, the AppBar and the rest of the content is properly laid out with the appropriate insets provided by fitsSystemWindows="true". In the second secreenshot, the insets disappear. Thanks for your time.
– DavidH
Nov 19 at 9:36












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Use the flag



 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}


Then push your view using these two methods



@SuppressLint("NewApi")
public static boolean hasImmersive(Context ctx) {

if (!cached) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
hasImmersive = false;
cached = true;
return false;
}
Display d = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);

int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;

DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);

int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;

hasImmersive = (realWidth > displayWidth) || (realHeight > displayHeight);
cached = true;
}

return hasImmersive;
}


Apply padding accordingly



 if (hasImmersive(this)) {
yourView.setPadding(0, 0, 0, getSoftButtonsBarHeight());

}


And get the height of System soft button



 @SuppressLint("NewApi")
private int getSoftButtonsBarHeight() {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}


Screenshots
Here is the screen shot



EDIT: To preserve the fitsSystemWindows="true" behaviour for the notification bar, add the FLAG_LAYOUT_NO_LIMITS and other flags after the window insets have been applied to your View which has fitsSystemWindows set to true. This will ensure that the insets have been applied normally before applying the no-limit flag.



yourViewWithFitsSystemWindows.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
if(insets.getSystemWindowInsetTop() == 0) return insets; // This is needed.
v.onApplyWindowInsets(insets);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// add other flags
return insets;
}
});


This, along with setting the bottom padding, gives the desired result.






share|improve this answer























  • Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
    – DavidH
    Nov 19 at 10:33











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370971%2fdraw-content-under-both-status-bar-and-navbar-while-maintaining-fitssystemwindow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Use the flag



 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}


Then push your view using these two methods



@SuppressLint("NewApi")
public static boolean hasImmersive(Context ctx) {

if (!cached) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
hasImmersive = false;
cached = true;
return false;
}
Display d = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);

int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;

DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);

int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;

hasImmersive = (realWidth > displayWidth) || (realHeight > displayHeight);
cached = true;
}

return hasImmersive;
}


Apply padding accordingly



 if (hasImmersive(this)) {
yourView.setPadding(0, 0, 0, getSoftButtonsBarHeight());

}


And get the height of System soft button



 @SuppressLint("NewApi")
private int getSoftButtonsBarHeight() {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}


Screenshots
Here is the screen shot



EDIT: To preserve the fitsSystemWindows="true" behaviour for the notification bar, add the FLAG_LAYOUT_NO_LIMITS and other flags after the window insets have been applied to your View which has fitsSystemWindows set to true. This will ensure that the insets have been applied normally before applying the no-limit flag.



yourViewWithFitsSystemWindows.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
if(insets.getSystemWindowInsetTop() == 0) return insets; // This is needed.
v.onApplyWindowInsets(insets);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// add other flags
return insets;
}
});


This, along with setting the bottom padding, gives the desired result.






share|improve this answer























  • Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
    – DavidH
    Nov 19 at 10:33















up vote
1
down vote



accepted










Use the flag



 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}


Then push your view using these two methods



@SuppressLint("NewApi")
public static boolean hasImmersive(Context ctx) {

if (!cached) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
hasImmersive = false;
cached = true;
return false;
}
Display d = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);

int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;

DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);

int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;

hasImmersive = (realWidth > displayWidth) || (realHeight > displayHeight);
cached = true;
}

return hasImmersive;
}


Apply padding accordingly



 if (hasImmersive(this)) {
yourView.setPadding(0, 0, 0, getSoftButtonsBarHeight());

}


And get the height of System soft button



 @SuppressLint("NewApi")
private int getSoftButtonsBarHeight() {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}


Screenshots
Here is the screen shot



EDIT: To preserve the fitsSystemWindows="true" behaviour for the notification bar, add the FLAG_LAYOUT_NO_LIMITS and other flags after the window insets have been applied to your View which has fitsSystemWindows set to true. This will ensure that the insets have been applied normally before applying the no-limit flag.



yourViewWithFitsSystemWindows.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
if(insets.getSystemWindowInsetTop() == 0) return insets; // This is needed.
v.onApplyWindowInsets(insets);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// add other flags
return insets;
}
});


This, along with setting the bottom padding, gives the desired result.






share|improve this answer























  • Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
    – DavidH
    Nov 19 at 10:33













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Use the flag



 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}


Then push your view using these two methods



@SuppressLint("NewApi")
public static boolean hasImmersive(Context ctx) {

if (!cached) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
hasImmersive = false;
cached = true;
return false;
}
Display d = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);

int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;

DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);

int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;

hasImmersive = (realWidth > displayWidth) || (realHeight > displayHeight);
cached = true;
}

return hasImmersive;
}


Apply padding accordingly



 if (hasImmersive(this)) {
yourView.setPadding(0, 0, 0, getSoftButtonsBarHeight());

}


And get the height of System soft button



 @SuppressLint("NewApi")
private int getSoftButtonsBarHeight() {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}


Screenshots
Here is the screen shot



EDIT: To preserve the fitsSystemWindows="true" behaviour for the notification bar, add the FLAG_LAYOUT_NO_LIMITS and other flags after the window insets have been applied to your View which has fitsSystemWindows set to true. This will ensure that the insets have been applied normally before applying the no-limit flag.



yourViewWithFitsSystemWindows.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
if(insets.getSystemWindowInsetTop() == 0) return insets; // This is needed.
v.onApplyWindowInsets(insets);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// add other flags
return insets;
}
});


This, along with setting the bottom padding, gives the desired result.






share|improve this answer














Use the flag



 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
w.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

}


Then push your view using these two methods



@SuppressLint("NewApi")
public static boolean hasImmersive(Context ctx) {

if (!cached) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
hasImmersive = false;
cached = true;
return false;
}
Display d = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

DisplayMetrics realDisplayMetrics = new DisplayMetrics();
d.getRealMetrics(realDisplayMetrics);

int realHeight = realDisplayMetrics.heightPixels;
int realWidth = realDisplayMetrics.widthPixels;

DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);

int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;

hasImmersive = (realWidth > displayWidth) || (realHeight > displayHeight);
cached = true;
}

return hasImmersive;
}


Apply padding accordingly



 if (hasImmersive(this)) {
yourView.setPadding(0, 0, 0, getSoftButtonsBarHeight());

}


And get the height of System soft button



 @SuppressLint("NewApi")
private int getSoftButtonsBarHeight() {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}


Screenshots
Here is the screen shot



EDIT: To preserve the fitsSystemWindows="true" behaviour for the notification bar, add the FLAG_LAYOUT_NO_LIMITS and other flags after the window insets have been applied to your View which has fitsSystemWindows set to true. This will ensure that the insets have been applied normally before applying the no-limit flag.



yourViewWithFitsSystemWindows.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
if(insets.getSystemWindowInsetTop() == 0) return insets; // This is needed.
v.onApplyWindowInsets(insets);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// add other flags
return insets;
}
});


This, along with setting the bottom padding, gives the desired result.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 16:14









DavidH

1,5631025




1,5631025










answered Nov 19 at 9:45









Sai Jayant

154212




154212












  • Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
    – DavidH
    Nov 19 at 10:33


















  • Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
    – DavidH
    Nov 19 at 10:33
















Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
– DavidH
Nov 19 at 10:33




Thanks. This works for the navigation bar. If we could also account for the notification bar inset too, then this answer would be complete. Do you have anything for that?
– DavidH
Nov 19 at 10:33


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53370971%2fdraw-content-under-both-status-bar-and-navbar-while-maintaining-fitssystemwindow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy