【问题标题】:New Android Design Library bug with AppBarLayout and Toolbar带有 AppBarLayout 和工具栏的新 Android 设计库错误
【发布时间】:2015-08-12 23:21:53
【问题描述】:

我正在使用基于此示例的新 Android 设计库 chrisbanes/cheesesquare in github 和 here

我已经运行了示例,但在 CheeseDetailActivity 中的工具栏出现问题。工具栏未按应有的方式显示。看看下面的图片:

首先你可以看到工具栏没有正确显示。

在第二张图片中,您可以看到工具栏正确显示,但通知栏是白色的。发生这种情况是因为我从 android:fitsSystemWindows="true"android.support.design.widget.CoordinatorLayout 中删除了 active_detail.xml

我认为fitsSystemWindows 应该是正确的,并且问题与android.support.design.widget.AppBarLayout 有关,但我不知道如何解决此问题。我尝试使用与notificationBar 高度相同的marginTop,但没有成功。

任何建议表示赞赏:)

这是activity_detail.xml的一部分:

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

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

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

【问题讨论】:

标签: android android-layout android-toolbar android-design-library


【解决方案1】:

看起来这是com.android.support:design:22.2.0 中的一个错误。 它将被修复,它被标记为未来版本。所以让我们希望它会很快。 有问题的链接: https://code.google.com/p/android/issues/detail?id=175240https://code.google.com/p/android/issues/detail?id=175069

【讨论】:

【解决方案2】:

在使用 windowActionBar 和 windowNoTitle 时遇到了同样的问题,并决定了我的问题。

<style name="AppTheme.base" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
       <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

【讨论】:

    【解决方案3】:

    以下是 API 21 的一些解决方法:

     if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
        marginResult = 0;
        int resourceId = getResources().getIdentifier(getString(R.string.identifier_status_bar_height), getString(R.string.identifier_dimen), getString(R.string.identifier_android));    
        if (resourceId > 0) {
            marginResult = getResources().getDimensionPixelSize(resourceId)*2;
         }
        CollapsingToolbarLayout.LayoutParams params = (CollapsingToolbarLayout.LayoutParams) mToolbar.getLayoutParams();
        params.topMargin -= marginResult;
        mToolbar.setLayoutParams(params);}
    

    【讨论】:

      【解决方案4】:

      使用 app 文件夹中的新版本 build.gradle 文件更改您的 Design Library,例如:

      编译'com.android.support:design:22.2.1'

      更新于+AndroidDevelopers

      我得到如下输出:

      它会帮助你。

      谢谢:)

      【讨论】:

      • 我没有测试过,但这一定是解决方案:)
      • android 支持设计库版本 22.2.1 没有为我解决问题。我在运行 Android 5.0 的设备上又遇到了麻烦。我必须更新到 23.1.0。现在可以使用了
      【解决方案5】:

      我有同样的问题,我的工具栏在 API 级别大于 21 时显示错误。我使用 android.support.v7.widget.Toolbar 作为 supportActionBar() 并且以下内容在片段中,请参见图片: on aplication start, toolbar is displaying wrongwhen i colapse android.support.design.widget.CollapsingToolbarLayout, the picture is not hidden completely

      当我将 android:fitsSystemWindows="true" 属性添加到工具栏所在视图的根元素时,我解决了这个问题。

      现在: toolbar is displaying normalpicture is hidden completely

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-19
        • 2015-08-23
        • 2020-05-04
        • 1970-01-01
        • 2015-09-23
        • 1970-01-01
        相关资源
        最近更新 更多