【问题标题】:androidx AppBarLayout AppBar top margin problemandroidx AppBarLayout AppBar上边距问题
【发布时间】:2019-09-13 13:25:39
【问题描述】:

为什么 AppBar 会上升?以及如何解决?

附加信息。

如果你启动activity然后立即这个fragment,那么一切都OK。

如果你开始活动,然后是一些片段,然后是这个片段,那么一切都很糟糕。

image. Android Studio layout designer - OK

image. API 16 - OK

xml布局code is here.

UPD。

<style name="EcommerceToolbar" parent="Widget.MaterialComponents.Toolbar">
        <item name="android:theme">@style/ThemeOverlay.MaterialComponents.Dark.ActionBar</item>
        <item name="popupTheme">@style/ThemeOverlay.MaterialComponents.Light</item>
    </style>

【问题讨论】:

  • 你能分享@style/EcommerceToolbar吗?
  • @es0329 请查看 UPD。

标签: android android-layout android-appbarlayout androidx appbar


【解决方案1】:

这是魔法。 创建 (v21) 样式并添加:

<item name="android:fitsSystemWindows">true</item>

【讨论】:

    【解决方案2】:

    尝试将layout_height 属性从AppBarLayout 更改为"?attr/actionBarSize"

    <com.google.android.material.appbar.AppBarLayout
           android:id="@+id/filter_list_appbar_layout"
           app:liftOnScroll="false"
           android:layout_width="match_parent"
           android:layout_height="?attr/actionBarSize"
           app:layout_constraintEnd_toEndOf="parent"
           app:layout_constraintStart_toStartOf="parent"
           app:layout_constraintTop_toTopOf="parent"
           >
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2012-11-15
      • 2016-08-15
      • 2011-05-24
      • 1970-01-01
      相关资源
      最近更新 更多