首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android状态栏滚动显示协调器布局,状态图标与工具栏标题重叠

Android状态栏滚动显示协调器布局,状态图标与工具栏标题重叠
EN

Stack Overflow用户
提问于 2015-11-30 08:53:17
回答 1查看 5.7K关注 0票数 17

在使用包含AppBarLayout (持有ToolBar和TabLayout)和ViewPager (持有片段)作为子级的协调器布局时,我遇到了一个问题。我希望顶部栏被隐藏时,向下滚动,并显示时,滚动回。然而,当我向下滚动时,状态栏也会向上滚动,将顶部栏留在状态图标的正下方,与它们重叠。

我尝试将android:fitsSystemWindows="true“添加到AppBarLayout和ViewPager中,但没有任何变化。

下面是使用的代码和显示这两种状态的快照:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-16 06:25:16

查看活动的主题,如果主题类似于@style/AppTheme.NoActionBar或一个没有ActionBar的主题,请尝试放置一个颜色,您必须具有类似如下的样式(V21):

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>    
</style>

将其更改为:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
票数 31
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33989984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档