0

我在Kitkat中实施本指南时遇到了问题。在棒棒糖一切正常: Lollipop如何使用DrawerLayout显示在ActionKar /工具栏上以及KitKat上的状态栏下?

但在奇巧工具栏不具有任何的顶部填充: Kitkat

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

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

但是我觉得我做错了什么。你有什么好的做法如何在KitKat上实现这种效果?

回答

0

layout-v21文件夹中的当前布局资源移到第一个屏幕截图上。然后尝试创建将具有相同height of the status bar

层次的只是一个占位符视图新的布局资源应该如下:

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

使用视图аbove你Toolbar,不会推动其状态栏的后面,因为它是在第二个屏幕截图,并会模仿你正在试图实现的填充

0

你有没有把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> 
+0

你可以提高通过添加代码或引用您的答案。 – dakab 2015-11-26 15:31:46

相关问题