java - 工具栏不会折叠,因为它应该在滚动期间使用 TabLayout

标签 java android android-toolbar

我在滚动过程中遇到工具栏(带有 TabLayout)的问题,因为它还隐藏了通知栏,使其看起来像工具栏的标题。

problem on scroll

这里是 Activity 的布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.testapp.MainActivity">

<android.support.design.widget.AppBarLayout
  android:id="@+id/appbar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:theme="@style/AppTheme.AppBarOverlay">

  <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/AppTheme.PopupOverlay">

  </android.support.v7.widget.Toolbar>

  <android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

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

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

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

我该如何解决这个问题?我见过像 Google Play 或 Phonograph 这样的应用没有这个问题。

提前致谢。

问候。

更新

这是我的 style.xml

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  <item name="colorPrimary">@color/colorPrimary</item>
  <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
  <item name="windowActionBar">false</item>
  <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

和 style.xml v21

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

关于MML13的response to remove fitsSystemWindows,可以,但是通知栏会掉色,变成白色。

enter image description here

enter image description here

最佳答案

试试这个。

更改此部分。

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

希望这对您有所帮助。

关于java - 工具栏不会折叠,因为它应该在滚动期间使用 TabLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36231888/

相关文章:

java - 传递一个非关联函数来减少

java - 在android中转换日期格式?

java - 线程 "main"java.lang.NoClassDefFoundError : org/apache/poi/ss/usermodel/Workbook while running jar file 中出现异常

java - 如何获取正在从 Android 中的下载管理器下载的文件的网络 uri

android - 是否可以阻止 Android Wear 设备安装该应用程序?

android - 如何将此图标添加到我的操作栏?

java - 扩展类在 Eclipse 中可以完美编译,但不能在 cmd 中编译

java - 安卓/MySQL : Spinner not populate data from MySQL

android - 在工具栏中心对齐文本

android - 应用程序标题下有关某些 Activity 的文字