简体   繁体   English

CollapsingToolbarLayout图像位于状态栏下方

[英]CollapsingToolbarLayout image below status bar

The problem here is that eventhough i haven't set fitsSystemWindows="true" to any of the tags in the xml, it still appear as if it has fitsSystemWindows="true". 这里的问题是,虽然我没有将fitsSystemWindows =“true”设置为xml中的任何标记,但它仍然看起来好像它具有fitsSystemWindows =“true”。 And in case you don't see the difference, it's in the status bar part. 如果你没有看到差异,它就在状态栏部分。

Result Now : 结果现在:

这是现在的结果

What I want : 我想要的是 :

这就是我要的

Additional Details: 额外细节:

  • I already set translucent status to true in styles.xml (v21) 我已经在styles.xml中将半透明状态设置为true(v21)

     <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="false" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <ImageView android:id="@+id/img" android:layout_width="match_parent" android:layout_height="250dp" android:fitsSystemWindows="false" android:scaleType="fitXY" android:src="@drawable/com_facebook_profile_picture_blank_portrait" app:layout_collapseMode="parallax" /> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:fitsSystemWindows="false" android:theme="@style/AppTheme.Toolbar" app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> 

     <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="a very long text, don't mind this, this is working as intended" /> 

v21/styles.xml V21 / styles.xml

<resources>

<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

</resources>

styles.xml styles.xml

<resources>

<style name="AppTheme" parent="AppTheme.Base">

</style>

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

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

<style name="AppTheme.Toolbar">
    <item name="android:textColorPrimary">@color/white</item>
    <item name="colorControlNormal">@color/white</item>
</style>

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

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

这真的令人困惑,但在我将fitsSystemWindows="true"到所有标签之后,它就起作用了。

You need set the transparency in /res/values-v21/styles.xml: 您需要在/res/values-v21/styles.xml中设置透明度:

<item name="android:statusBarColor">@android:color/transparent</item>

Or set the transparency programmatically: 或者以编程方式设置透明度:

getWindow().setStatusBarColor(Color.TRANSPARENT);

See, the problem isn't the styling, but collapsing toolbar itself. 看,问题不是样式,而是折叠工具栏本身。 I don't know how to fix it but I can help you figure out why it is happening. 我不知道如何解决它,但我可以帮助你弄清楚它为什么会发生。 Trying to make status bar transparent with view pager works perfect. 尝试通过视图寻呼机使状态栏透明工作非常完美。 Now what you see here is, making the status bar color transparent (it is not fully transparent to show the white icons though), enable the view pager to take place behind the status bar too. 现在您在这里看到的是,使状态栏颜色透明(虽然显示白色图标不完全透明),也使得视图寻呼机也可以在状态栏后面进行。 Now when you do the same with your app containing collapsing toolbar, the status bar gets partially transparent and show collapsing toolbar as background. 现在,当您对包含折叠工具栏的应用程序执行相同操作时,状态栏将部分透明,并将折叠工具栏显示为背景。 But problem here is collapsing toolbar's default is primaryColorLight or dark or the one you specified, but not the image, that's why you always see the dark color of toolbar behind status bar but not the image. 但这里的问题是折叠工具栏的默认值是primaryColorLight或者黑暗或你指定的那个,但不是图像,这就是为什么你总是看到状态栏后面的工具栏的深色而不是图像。

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

相关问题 状态栏正在使用CollapsingToolbarLayout滚动 - Status bar is scrolling with CollapsingToolbarLayout 透明状态栏和CollapsingToolbarLayout - Transparent status bar and CollapsingToolbarLayout CollapsingToolbarLayout工具栏位于状态栏中 - CollapsingToolbarLayout toolbar is in the status bar 如何将插图应用于带有图像的 CollapsingToolbarLayout,因此工具栏中的图像绘制在状态栏后面? - How to apply insets to CollapsingToolbarLayout with an image inside, so image in toolbar is drawn behind status bar? 状态栏下方的CoordinatorLayout + CollapsingToolbarLayout滚动 - CoordinatorLayout + CollapsingToolbarLayout scrolling underneath the status bar CollapsingToolbarLayout在API 26中的图像下显示栏 - CollapsingToolbarLayout shows bar under image in API 26 CollapsingToolBarLayout - 状态栏稀松布颜色不会改变 - CollapsingToolBarLayout - status bar scrim color doesn't change 当CollapsingToolbarLayout处于片段中时,不能有透明的状态栏 - Cannot have a transparent status bar when CollapsingToolbarLayout is in a fragment Android Studio:如何在collapsingtoolbarlayout中创建半透明状态栏? - Android Studio: How to create a translucent status bar within collapsingtoolbarlayout? 将工具栏放在状态栏下方 - place toolbar below status bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM