Actual result: The status bar appears over the action bar Toolbar
and the MenuItem
inside the action bar is cut off. Note: "Test" is the action bar's title
.
Expected result:
The top bound of the action bar Toolbar
should appear directly below the bottom bound of the status bar and any MenuItem
s inside the action bar should be completely visible.
Activity's XML layout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/background"
tools:ignore="ContentDescription"/>
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</FrameLayout>
The action bar title
and MenuItem
are added at runtime.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
setSupportActionBar((Toolbar) findViewById(R.id.action_bar));
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setTitle("Test");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_test, menu);
return true;
}
Before I added fitsSystemWindows="true"
to the Toolbar
view, the status bar still overlayed the action bar, but the 'SKIP' MenuItem
was vertically centered in the action bar, causing it to appear partially underneath the status bar. I expected the fitsSystemWindows=true
flag to give me my expected result (mentioned above), but it did not. It's as if fitsSystemWindows="true"
correctly positioned the 'SKIP' button but did not adjust the position of the action bar itself. Anyone know what might be the issue here?
EDIT: I realize that I could remove fitsSystemWindows="true"
and add a marginTop="...statusBarHeight"
to the Toolbar
view, but I am looking for the a cleaner way to solve this.