android - 工具栏重叠在状态栏下方

标签 android xml android-layout material-design material-components-android

我想在我的 Activity 中使用 appcompat v21 工具栏。但我正在实现的工具栏重叠在状态栏下方。我该如何修复它?

overlapping toolbar

这是 Activity 布局 xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>

工具栏 View :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary" />

主题风格:

<style name="AppTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>

最佳答案

在布局的 Root View 中使用 android:fitsSystemWindows="true" (在您的情况下为 LinearLayout)。

关于android - 工具栏重叠在状态栏下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46357603/

相关文章:

android - getWidth 在 Fragment 中返回 0,getPaddingLeft 返回非零

android - 带有水平进度条的启动画面

java - Android Studio Tab View 灰色主题颜色

Java 检查一个字符串是有效的 JSON 还是有效的 XML 或者两者都不是

android - 如何让线性布局占据 ScrollView 的整个空间?

java - 使用 Intents 进行 View 切换后信息不会保存(android)

java - 在 HashMap 中存储不同类型的参数

android - notifyDataSetChanged() 导致 IndexOutOfBoundsException

android - 仅在全屏模式下打开键盘布局调整大小

python - 如何使 xml.sax 对其 DTD 请求使用 HTTP 代理?