【发布时间】:2016-05-23 02:38:59
【问题描述】:
几天前我更新了我的 android 工作室并开始使用 CoordinatorLayout 和 CollapsingToolbarLayout 只是尝试一些东西。
似乎工具栏稀松布颜色覆盖了状态栏初始颜色和状态栏稀松布颜色(从 xml 和代码都尝试过)
初始状态:
开始滚动:
滚动到折叠:
所以问题是:
如何防止工具栏在折叠时覆盖状态栏(甚至不让我正在折叠的图像超出它)。
折叠后如何更改状态栏颜色
我遇到的另一个问题是我给工具栏提供了初始颜色,而不仅仅是稀松布颜色,因为我希望工具栏位于图片上方,而是它会出现在图片的顶部,并且会覆盖其中的一部分以及任何内容那会在它后面崩溃
在 xml 中为工具栏添加了颜色/样式:
- 有没有什么办法可以让工具栏从一开始就放在图片上方,然后直接折叠图片? (考虑过可能保持工具栏固定并在图像之前进行框架布局,但它仍然会在状态栏区域崩溃,这是主要问题。)
主要活动xml:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim = "?attr/colorPrimary"
app:statusBarScrim="?attr/colorAccent" --------> not changing
android:id="@+id/my_ctl">
<ImageView
android:id="@+id/image"
android:src="@drawable/flights"
android:layout_width="match_parent"
android:layout_height="250dp"
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/AppTheme.PopupOverlay"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<include layout="@layout/content_main" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
MainActivity.java:
CollapsingToolbarLayout ctl = (CollapsingToolbarLayout) findViewById(R.id.my_ctl);
//ctl.setContentScrimColor(Color.RED);
ctl.setStatusBarScrimColor(Color.BLUE); --------> not working
ctl.setTitle("blabla");
【问题讨论】:
标签: android android-toolbar android-6.0-marshmallow android-collapsingtoolbarlayout