Answer the question
In order to leave comments, you need to log in
How to correctly catch the CollapsingToolbarLayout event?
There is the following layout:
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:statusBarScrim="?attr/colorPrimaryDark">
<com.daimajia.slider.library.SliderLayout
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@android:color/white"
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:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener()
{
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
int toolbarHeight = toolbar.getHeight();
int appBarHeight = appBarLayout.getHeight();
int flagLight = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
int flag = appBarLayout.getSystemUiVisibility();
if (appBarHeight + verticalOffset > 2 * toolbarHeight) {
if ((flag ^ flagLight) == flagLight) {
appBarLayout.setSystemUiVisibility(flag | flagLight);
}
return;
}
if ((flag & flagLight) == flagLight) {
appBarLayout.setSystemUiVisibility(flag ^ flagLight);
}
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question