In landscape mode, I am using
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
to show and hide navigation bar.
When I create Snackbar while navigation is showing
Snackbar bar = Snackbar.make(snackbarContainer, "exiting", Snackbar.LENGTH_INDEFINITE);
bar.setAction("Testing", new View.OnClickListener() {
@Override
public void onClick(View v) {
//no-op
}
});
bar.show();
The Snackbar's action text is being covered by the navigation bar. Is there a way to adjust snackbar's width automatically based on whether the navigation bar is showing or not?
Possibly you are searching for this:
private void displaySnackBarWithBottomMargin(Snackbar snackbar, int sideMargin, int marginBottom) {
final View snackBarView = snackbar.getView();
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) snackBarView.getLayoutParams();
params.setMargins(params.leftMargin + sideMargin, params.topMargin, params.rightMargin + sideMargin, params.bottomMargin + marginBottom);
snackBarView.setLayoutParams(params);
snackbar.show();
}
Actually found it at: https://stackoverflow.com/a/34844669/371749
If you add the margin bottom from the navigation bar height (48dp) it perfectly appears above the navigation bar.
You could add a CoordinatorLayout
(for instance when using a ConstraintLayout
, tie it to the bottom of the parent).
Next, give the id of the CoordinatorLayout
to the Snackbar.make(...)
function (or any child in the CoordinatorLayout
).
A snackbar will iterate the views from the current one up until it finds a CoordinatorLayout
and attach itself to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With