31

github とhereのこのサンプルchrisbanes/cheesesquareに基づいて、新しい Android デザイン ライブラリを使用しています。

サンプルを実行しましたが、CheeseDetailActivity 内のツールバーに問題があります。ツールバーが正しく表示されません。以下の画像をご覧ください。

最初の画像では、ツールバーが正しく表示されていないことがわかります。

ここに画像の説明を入力

2 番目の画像では、ツールバーは正しく表示されていますが、通知バーは白くなっています。これは、activvty_detail.xmlandroid:fitsSystemWindows="true"から削除したために発生します。android.support.design.widget.CoordinatorLayout

ここに画像の説明を入力

fitsSystemWindowsそれは真実であり、問​​題は関連していると思いますがandroid.support.design.widget.AppBarLayout、この問題を解決する方法がわかりません。marginTopと同じ高さで試してみましnotificationBarたが、うまくいきませんでした。

どんな提案でも大歓迎です:)

これは次の一部です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>
4

5 に答える 5

1

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>
于 2015-06-26T00:53:34.470 に答える
0

私は同じ問題を抱えていました.21を超えるAPIレベルでツールバーが間違って表示されていました.android.support.v7.widget.ToolbarをsupportActionBar()として使用していました.以下のコンテンツはフラグメントです.写真を参照してください .間違っていてandroid.support.design.widget.CollapsingToolbarLayout を折りたたむと、画像が完全に非表示になりません

ツールバーが配置されているビューのルート要素に android:fitsSystemWindows="true" 属性を追加したときに、これを解決しました。

現在: ツールバーは正常に表示され、 画像は完全に非表示になっています

于 2016-01-27T22:08:16.630 に答える
0

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);}
于 2015-07-10T09:25:05.133 に答える