【问题标题】:How do I use DrawerLayout to display over the ActionBar/Toolbar and under the status bar on KitKat?如何使用 DrawerLayout 在 KitKat 的 ActionBar/Toolbar 和状态栏下方显示?
【发布时间】:2015-01-21 01:44:41
【问题描述】:

我在 Kitkat 中实施此准则时遇到问题。在 Lollipop 上一切正常:

但在 Kitkat Toolbar 上没有任何顶部填充:

我可以使用https://github.com/jgilfelt/SystemBarTint 库解决这个问题:

SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
mainView.setPadding(0, config.getPixelInsetTop(false), config.getPixelInsetRight(), config.getPixelInsetBottom());

但我觉得我做错了什么。您有什么好的做法可以在 KitKat 上实现这种效果吗?

【问题讨论】:

    标签: android navigation-drawer android-4.4-kitkat material-design android-toolbar


    【解决方案1】:

    layout-v21 文件夹中的当前布局资源移动到第一个屏幕截图中的状态。然后尝试创建新的布局资源,该资源将仅具有相同 height of the status bar 的占位符视图

    层次结构应该如下:

    --Top layout
      --<view layout_height="25dip"...>
      -- Toolbar
      -- the rest of the views
    

    使用Toolbar 上方的视图,不会将其推到状态栏后面,因为它在第二个屏幕截图中,并且会模仿您尝试实现的填充

    【讨论】:

      【解决方案2】:

      您是否将fitsSystemWindow 设置为true?将其设置为 false 会将工具栏带回状态栏下方。

      您看到 Kitkat 的效果是因为您设置了半透明状态栏并适合系统窗口在其下方。

      例如,在您的布局 XML 文件中:

      <android.support.v4.widget.DrawerLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/drawer_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/white"
          android:fitsSystemWindows="false">
      
          <android.support.v7.widget.Toolbar
              android:background="@color/blue"
              android:layout_width="match_parent"
              android:layout_height="?android:attr/actionBarSize"
              android:id="@+id/action_bar"/>
      
          <!-- YOUR CONTENT HERE -->
      
          <!-- YOUR NAVIGATION VIEW HERE -->
      
      </android.support.v4.widget.DrawerLayout>
      

      【讨论】:

      • 您可以通过添加代码或参考来改进您的答案。
      猜你喜欢
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 2016-11-07
      相关资源
      最近更新 更多