Android Studio AppBarLayout不在屏幕顶部

yzuktlbb  于 2022-11-16  发布在  Android
关注(0)|答案(3)|浏览(187)

我的问题是,AppBarLayout和工具栏没有出现在屏幕的顶部,因此挡住了所包含内容的视图。它可以在图像中看到。我确信我只是错过了一些东西。

另外,下面是xml代码。

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<include layout="@layout/content_search" />

EDIT:主题设为NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

它看起来像这样:

avwztpqn

avwztpqn1#

您应该将主题设置为任何NoActionBar主题,例如

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorSecondary</item>
        <item name="colorAccent">@color/google_blue</item>
    </style>
gupuwyp2

gupuwyp22#

res/values/styles中将您的风格设置为NoActionBar主题,例如:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

现在,您应该会失去常规ActionBar,而可以使用工具栏。
编辑:OP试图完成的是将包含布局放置在CoordinatorLayout中的AppBar布局下方。这是通过将app:layout_behavior="@string/appbar_scrolling_view_behavior"添加到包含布局来完成的。

p3rjfoxz

p3rjfoxz3#

设置layout_width和layout_height以匹配包含布局的父布局(包含布局内部的布局)。

相关问题