简体   繁体   English

AppBarLayout和Toolbar的新Android设计库错误

[英]New Android Design Library bug with AppBarLayout and Toolbar

I am using the new Android Design Library based on this example chrisbanes/cheesesquare in github and here 我在github和这里使用基于这个例子的新的Android设计库chrisbanes / cheesesquare

I have run the example and I am having problems with Toolbar inside CheeseDetailActivity. 我运行了这个例子,我遇到了CheeseDetailActivity里面的工具栏问题。 The toolbar isnt shown as it should. 工具栏未按预期显示。 Have a look at the images below: 看看下面的图片:

At first image you can see the toolbar isn't shown correctly. 在第一张图像中,您可以看到工具栏未正确显示。

在此输入图像描述

At the second image you can see that the toolbar is shown correctly but the notification bar is white. 在第二个图像中,您可以看到工具栏显示正确但通知栏为白色。 This happens because I removed from actiivty_detail.xml android:fitsSystemWindows="true" from android.support.design.widget.CoordinatorLayout 发生这种情况是因为我从android.support.design.widget.CoordinatorLayout删除了actiivty_detail.xml android:fitsSystemWindows="true"

在此输入图像描述

I think that fitsSystemWindows should be true and the problem is related with android.support.design.widget.AppBarLayout but I don't have any idea how I can fix this problem. 我认为fitsSystemWindows应该是真的,问题与android.support.design.widget.AppBarLayout有关,但我不知道如何解决这个问题。 I tried with marginTop with the same height as notificationBar but it didn't work. 我尝试使用marginTop ,其高度与notificationBar相同但不起作用。

Any suggestion is appreciated :) 任何建议表示赞赏:)

This is a part of the activity_detail.xml : 这是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>

Change your Design Library with New Version build.gradle file in app folder like: 使用app文件夹中的新版本build.gradle文件更改您的设计库 ,例如:

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

As Updated in +AndroidDevelopers 已在+ AndroidDevelopers中更新

I got output like: 我有输出像:

在此输入图像描述

It will helps you. 它会帮助你。

Thanks :) 谢谢 :)

Looks like this is a bug in com.android.support:design:22.2.0 . 看起来这是com.android.support:design:22.2.0一个错误。 It will be fixed, it's marked as future release. 它将被修复,它被标记为将来的版本。 So lets hope it will be soon. 所以,希望它很快就会到来。 Links with issues: https://code.google.com/p/android/issues/detail?id=175240 and https://code.google.com/p/android/issues/detail?id=175069 问题链接: https//code.google.com/p/android/issues/detail?id = 175240https://code.google.com/p/android/issues/detail?id=175069

had the same problem put in style with windowActionBar and windowNoTitle and decided my problem. 用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>

Here is some working workaround for API 21: 以下是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);}

I had same problem, my toolbar was displaying wrong on API level greater than 21. I was using android.support.v7.widget.Toolbar as supportActionBar() and below content is in fragment, see pictures: on aplication start, toolbar is displaying wrong and when i colapse android.support.design.widget.CollapsingToolbarLayout, the picture is not hidden completely 我有同样的问题,我的工具栏在API级别上显示错误大于21.我使用android.support.v7.widget.Toolbar作为supportActionBar(),下面的内容是片段,请参阅图片: 在aplication start,工具栏显示错了当我陷入android.support.design.widget.CollapsingToolbarLayout时,图片并未完全隐藏

I resolved this when i added android:fitsSystemWindows="true" attribute to the root element of view where Toolbar is located. 当我将android:fitsSystemWindows =“true”属性添加到工具栏所在的视图的根元素时,我解决了这个问题。

Now: toolbar is displaying normal and picture is hidden completely 现在: 工具栏显示正常图片完全隐藏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM