android 中工具栏未固定在顶部且小于操作栏大小

tool bar is not pinned to the top and smaller than action bar size in android

我在几个 XML 文件中有相同的代码。在某些工具栏中,工具栏显示为我想要的(如操作栏),而在其他工具栏中,工具栏较小且浮动。看照片:

我的屏幕工具栏xml:

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

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

    </android.support.design.widget.AppBarLayout>

我的app_barxml:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

样式:

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

您应该在 AppBarLayout 的根目录中添加填充 只需删除填充。

toolbar parent;
parent.setContentInsetsAbsolute(0, 0);

试试这个!