工具栏重叠在状态栏下方

Eme*_*men 145 xml android android-layout

我希望在我的活动中有appcompat v21工具栏.但我正在实现的工具栏重叠在状态栏下方.我该如何解决?

重叠工具栏

这是活动布局xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

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

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

工具栏视图:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary" />
Run Code Online (Sandbox Code Playgroud)

主题风格:

<style name="AppTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

Soh*_*aib 250

android:fitsSystemWindows="true"在布局的根视图中使用(在您的情况下为LinearLayout).而且android:fitsSystemWindows是一个

内部属性,用于根据系统窗口(如状态栏)调整视图布局.如果为true,则调整此视图的填充以为系统窗口留出空间.仅在此视图位于非嵌入活动中时才会生效.

必须是布尔值,"true"或"false".

这也可能是对包含此类型值的资源(格式为"@ [package:] type:name")或主题属性(格式为"?[package:] [type:] name")的引用.

这对应于全局属性资源符号fitsSystemWindows.

  • @AimanB你可以通过在主题中设置为"<item name ="android:fitsSystemWindows"> true </ item>来全局设置它 (22认同)
  • @Samir这有副作用,如[本评论]所述(http://stackoverflow.com/questions/20578780/taking-advantage-of-the-translucent-status-bar-in-android-4-4-奇巧#comment32445193_21130544) (13认同)
  • 即使我们在root布局中添加了android:fitsSystemWindows ="true",如果你的样式包含<item name ="android:statusBarColor"> @ android:color/transparent </ item>,这个问题也会出现.刚刚提到那些正在阅读这个问题的人. (9认同)
  • 我有同样的问题,android:fitsSystemWindows ="true"对我没用.任何人都有解决方案,请发布. (3认同)
  • 这就像一个魅力,但我必须删除工具栏本身中的“android:fitsSystemWindows”。 (2认同)

Zah*_*.HY 17

只需将其设置为v21/styles.xml文件即可

 <item name="android:windowDrawsSystemBarBackgrounds">true</item>
 <item name="android:statusBarColor">@color/colorPrimaryDark</item>
Run Code Online (Sandbox Code Playgroud)

并确定

 <item name="android:windowTranslucentStatus">false</item>
Run Code Online (Sandbox Code Playgroud)


ind*_*_gt 10

没有一个答案对我有用,但这是我android:fitSystemWindows在根视图上设置后最终工作的(我在样式v21中设置了这些):

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">false</item>
Run Code Online (Sandbox Code Playgroud)

确保您没有以下行,因为默认情况下AS放置它:

<item name="android:statusBarColor">@android:color/transparent</item>
Run Code Online (Sandbox Code Playgroud)


Muz*_*Muz 9

对我来说,问题是我从一个例子中复制并使用了一些东西

<item name="android:windowTranslucentStatus">true</item>
Run Code Online (Sandbox Code Playgroud)

只是删除这个修复我的问题.


ano*_*an2 9

没有一个答案对我有用,但这就是我设置后最终起作用的方法:

android:fitsSystemWindows="false"
Run Code Online (Sandbox Code Playgroud)

在父活动布局文件中,很多地方都不建议这样做,但它对我有用并节省了我的一天


1'h*_*afs 5

我从/res/values-v21/styles.xml中删除了下面提到的所有行,现在一切正常。

 <item name="android:windowDrawsSystemBarBackgrounds">true</item>
 <item name="android:statusBarColor">@android:color/transparent</item>


 <item name="windowActionBar">false</item>
 <item name="android:windowDisablePreview">true</item>

 <item name="windowNoTitle">true</item>

 <item name="android:fitsSystemWindows">true</item>
Run Code Online (Sandbox Code Playgroud)