Skip to content

Instantly share code, notes, and snippets.

@chandruscm
Last active August 14, 2019 13:58
Show Gist options
  • Save chandruscm/03756a5ca3ba520d828615453de414d4 to your computer and use it in GitHub Desktop.
Save chandruscm/03756a5ca3ba520d828615453de414d4 to your computer and use it in GitHub Desktop.
activity_menu_app_bar_1.xml produces the desired effect, but the toolbar moves up: as per the height set in the empty CollapsingToolbarLayout before adding the elevation. activity_menu_app_bar_2.xml does not work, it adds elevation by default without scrolling.
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:id="@+id/activity_menu_app_bar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:minHeight="0.1dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"/>
<include layout="@layout/activity_menu_toolbar"/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:id="@+id/activity_menu_app_bar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="1dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include layout="@layout/activity_menu_toolbar"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_menu_toolbar">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_normal"
android:background="?android:selectableItemBackgroundBorderless"
android:src="@drawable/ic_search"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:id="@+id/activity_menu_toolbar_search_button"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="@dimen/font_large"
android:textStyle="bold"
android:textAllCaps="true"
android:textColor="@color/textLight"
android:layout_centerInParent="true"
android:id="@+id/activity_menu_toolbar_title_text"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_normal"
android:background="?android:selectableItemBackgroundBorderless"
android:src="@drawable/ic_settings"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:id="@+id/activity_menu_toolbar_bookmark_button"/>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0.8dp"
android:layout_alignParentBottom="true"
android:background="@color/menuDivider"/>
</RelativeLayout>
@AndroidDeveloperLB
Copy link

Say, why does AppBarLayout have a default stateListAnimator ? When does it ever get changed? Which states does it have, by default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment