工具栏在状态栏下方重叠 [英] Toolbar overlapping below status bar

查看:38
本文介绍了工具栏在状态栏下方重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的活动中使用 appcompat v21 工具栏.但是我正在实施的工具栏在状态栏下方重叠.我该如何解决?

I want to have appcompat v21 toolbar in my activity. But the toolbar I'm implementing is overlapping below status bar. How can I fix it?

这是活动布局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>

工具栏视图:

<?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" />

主题风格:

<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>

推荐答案

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

Use android:fitsSystemWindows="true" in the root view of your layout (LinearLayout in your case). And android:fitsSystemWindows is an

根据系统窗口调整视图布局的内部属性,例如作为状态栏.如果为 true,则调整此视图的填充以离开系统窗口的空间.仅在此视图中时才会生效非嵌入式活动.

internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

必须是布尔值,真"或假".

Must be a boolean value, either "true" or "false".

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

这个对应全局属性资源符号适合系统Windows.

This corresponds to the global attribute resource symbol fitsSystemWindows.

这篇关于工具栏在状态栏下方重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆