MyActionBar: Use window inset listener for top inset, rather than the status bar height dimension.

This commit is contained in:
Andreas Schildbach 2021-02-04 20:13:35 +01:00
parent fcd08d55c8
commit 0d9fb4abd4

View file

@ -67,6 +67,11 @@ public class MyActionBar extends LinearLayout {
this.context = context; this.context = context;
this.res = getResources(); this.res = getResources();
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
setOnApplyWindowInsetsListener((v, insets) -> {
v.setPadding(0, insets.getSystemWindowInsetTop(), 0, 0);
return insets;
});
} }
@Override @Override
@ -81,11 +86,6 @@ public class MyActionBar extends LinearLayout {
progressView = findViewById(R.id.action_bar_progress); progressView = findViewById(R.id.action_bar_progress);
progressButton = findViewById(R.id.action_bar_progress_button); progressButton = findViewById(R.id.action_bar_progress_button);
progressImage = findViewById(R.id.action_bar_progress_image); progressImage = findViewById(R.id.action_bar_progress_image);
// Make sure action bar isn't stuck under a transparent status bar.
final int statusHeight = res
.getDimensionPixelSize(res.getIdentifier("status_bar_height", "dimen", "android"));
setPadding(getPaddingLeft(), getPaddingTop() + statusHeight, getPaddingRight(), getPaddingBottom());
} }
public void setDrawer(final OnClickListener onClickListener) { public void setDrawer(final OnClickListener onClickListener) {