实际结果:状态栏出现在操作栏
在我将
编辑:我意识到我可以删除
Toolbar
上方,操作栏中的MenuItem
被裁剪了。注意:“Test”是操作栏的title
。
期望结果:操作栏Toolbar
的顶部边界应直接出现在状态栏底部边界下方,并且操作栏中的任何MenuItem
都应完全可见。
活动的XML布局:
<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>
运行时添加了操作栏title
和MenuItem
。
@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;
}
在我将
fitsSystemWindows =“true”
添加到Toolbar
视图之前,状态栏仍会覆盖操作栏,但“SKIP” MenuItem
在操作栏中垂直居中,导致它部分出现在状态栏下方。我期望fitsSystemWindows = true
标志可以给我预期的结果(如上所述),但事实并非如此。好像fitsSystemWindows =“true”
正确定位了“跳过”按钮,但没有调整操作栏本身的位置。有人知道这里可能有什么问题吗?编辑:我意识到我可以删除
fitsSystemWindows =“true”
并添加marginTop =“... statusBarHeight”
到Toolbar
视图,但是我正在寻找更清洁的解决方法。
ImageView
。在操作栏下面没有其他视图。 - Ryan