I have a toolbar and I want to change the background image when switching between this toolbar in activity. In addition, the toolbar is fixed and contained in an < include >.
layout_toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/ic_customer_toolbar"
android:gravity="center"
app:navigationIcon="#drawable/ic_left_arrow"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/linearLayoutToolbarContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingEnd="75dp"
android:paddingRight="75dp"
tools:ignore="Orientation">
<TextView
android:id="#+id/textViewSectionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:fontFamily="#font/roboto_regular"
android:gravity="center"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
android:visibility="gone"
tools:text="Section Title" />
</RelativeLayout>
<ProgressBar
android:id="#+id/toolbarProgressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:padding="#dimen/app_padding_tiny"
android:visibility="invisible" />
<Button
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="22dp"
android:background="#drawable/ic_menu_button" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
and my
activity_customer.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/layout_toolbar"></include>
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#drawable/ic_tabview"
app:tabGravity="fill"
app:tabIndicatorHeight="4dp"
app:tabMode="scrollable"
app:tabTextAppearance="#style/TabLayoutTextStyle"
app:tabTextColor="#color/textmavi"
app:theme="#style/ThemeOverlay.AppCompat.Light">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/appbarLayout">
</android.support.v4.view.ViewPager>
<android.support.design.widget.FloatingActionButton
android:id="#+id/editCustomerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:clickable="true"
app:srcCompat="#drawable/ic_icon_edit"
tools:ignore="VectorDrawableCompat" />
</RelativeLayout>
I have an activity_sale.xml file like this one and I want it to be different from the toolbar color for the activity_customer toolbar. How can I do that?
Related
i want to remove the divider that is shown in sc.
look at the green arrows
(i have 5 fragment that are loaded in the viewpager and my frame,when i touch the tabs ,fragments change)
and this is my xml code for this activity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ir.myinsta.myinstaapp.MainActivity">
<android.support.v7.widget.CardView
android:id="#+id/header_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_height">
<RelativeLayout
android:id="#+id/actionbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/my_gradiant">
<android.support.v7.widget.Toolbar
android:id="#+id/main_toolbar"
style="#style/MyDrawerArrowToggle"
android:layout_width="#dimen/toolbar_height"
android:layout_height="#dimen/toolbar_height"
android:layout_alignParentRight="true">
</android.support.v7.widget.Toolbar>
<ImageView
android:id="#+id/helpImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="#+id/main_toolbar"
android:clickable="true"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:id="#+id/gemLayout"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:clickable="true"
android:gravity="left"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"
android:src="#drawable/diamond_white" />
<TextView
android:id="#+id/gemCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:layout_gravity="center_vertical"
android:textColor="#color/white" />
</LinearLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:elevation="5dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="0dp"
android:background="#color/white"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="#00000000"
app:tabIndicatorHeight="0dp" />
<android.support.v4.view.ViewPager
android:id="#+id/myViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/tab_layout"
android:layout_below="#id/header_layout">
</android.support.v4.view.ViewPager>
<FrameLayout
android:id="#+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/header_layout"></FrameLayout>
<RelativeLayout
android:id="#+id/centerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="150dp" />
</RelativeLayout>
I don't know this is a divider or elevation.please help me.
using styles? or what?
Try to add app:elevation="0dp" in your ToolBar.
Like this :-
<android.support.v7.widget.Toolbar
android:id="#+id/main_toolbar"
style="#style/MyDrawerArrowToggle"
app:elevation="0dp"
android:layout_width="#dimen/toolbar_height"
android:layout_height="#dimen/toolbar_height"
android:layout_alignParentRight="true">
</android.support.v7.widget.Toolbar>
Or you can use:-
<android.support.design.widget.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
</android.support.design.widget.AppBarLayout>
I'm trying to collapse my header view while scrolling up the view pager.
In the following image relativelayout3 is the layout I want to collapse..
Something like playstore preview image collapse in app page..
I tried searching and the following line in relativelayout3, But it didnt work
app:layout_scrollFlags="scroll|enterAlways"
And this my complete xml,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout3"
app:layout_scrollFlags="scroll|enterAlways"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:id="#+id/toolbar"
android:background="#color/cornflower_blue_two"
android:elevation="5dp">
<ImageButton
android:id="#+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="10dp"
android:background="#null"
android:src="#drawable/ic_dots_vertical" />
<ImageButton
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginEnd="5dp"
android:layout_marginStart="10dp"
android:background="#null"
android:src="#drawable/ic_arrow_left" />
</RelativeLayout>
<ss.com.bannerslider.views.BannerSlider
android:id="#+id/slider"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="#color/blue"
android:layout_below="#id/toolbar"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/relativeLayout3">
<TextView
android:id="#+id/product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Blah Blah"
android:textColor="#color/dark_gray"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="#+id/brand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/product"
android:layout_below="#+id/product"
android:text="Blah inc."
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/ratings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/brand"
android:layout_alignBottom="#+id/brand"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/brand"
android:background="#color/ratings"
android:paddingEnd="10dp"
android:paddingStart="10dp"
android:text="4.7"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/brand"
android:layout_marginTop="14dp"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/tabLayout" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Consider using CollapsingToolbarLayout. Please refer Collapsing Toolbar Example.
<android.support.design.widget.CoordinatorLayout
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="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/cartoon"
android:scaleType="centerCrop"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
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" />
</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:background="#ffe5e5"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Output
More Reference
I am having following issues when using bottomsheet with snackbar:
Whenever Snackbar is shown then Bottoomsheet is getting inflated first.
Refer screenshot below
Here is the layout file, id of bottomSheet is details_bottom_sheet
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fitsSystemWindows="true"
tools:context="project.udacity.com.investishare.ui.ItemsDetailActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_subhead_desc"
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/subheading_margin_bottom"
android:layout_marginLeft="#dimen/subheading_margin_left"
android:layout_marginStart="#dimen/subheading_margin_left"
android:drawableLeft="#drawable/ic_subtree"
android:drawablePadding="#dimen/subheading_drawable_padding"
android:drawableStart="#drawable/ic_subtree"
android:gravity="center_vertical"
android:paddingLeft="#dimen/subheading_padding_left"
android:paddingStart="#dimen/subheading_padding_left"
android:textColor="#color/color_white"
android:textSize="#dimen/tv_subhead_desc_text_size"
tools:text="#string/tv_subhead_desc_sample_text" />
<TextView
android:id="#+id/tv_shared_with"
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_subhead_desc"
android:layout_marginBottom="#dimen/subheading_margin_bottom"
android:layout_marginLeft="#dimen/subheading_margin_left"
android:layout_marginStart="#dimen/subheading_margin_left"
android:drawableLeft="#drawable/ic_shared_white"
android:drawablePadding="#dimen/subheading_drawable_padding"
android:drawableStart="#drawable/ic_shared_white"
android:gravity="center_vertical"
android:paddingEnd="#dimen/tv_shared_with_padding_right"
android:paddingLeft="#dimen/subheading_padding_left"
android:paddingRight="#dimen/tv_shared_with_padding_right"
android:paddingStart="#dimen/subheading_padding_left"
android:textColor="#color/color_white"
android:textSize="#dimen/tv_shared_with_text_size"
tools:text="#string/tv_shared_with_sample_text" />
<ImageView
android:id="#+id/iv_remove_sharing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/tv_subhead_desc"
android:layout_marginEnd="#dimen/subheading_drawable_padding"
android:layout_marginRight="#dimen/subheading_drawable_padding"
android:clickable="true"
android:contentDescription="#string/cd_remove_sharing"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:padding="#dimen/subheading_drawable_padding"
android:src="#drawable/ic_cancel_white" />
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_items_detail" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_detail_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_shared_white" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="450dp"
android:id="#+id/details_bottom_sheet"
android:elevation="16dp"
android:background="#color/color_white"
app:layout_behavior="#string/bottom_sheet_behavior">
<TextView
android:id="#+id/bottom_sheet_header"
style="#style/Base.TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/textview_bg"
android:padding="10dp"
android:text="hello"
android:textSize="24sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_bottom_sheet"
android:layout_width="match_parent"
android:layout_below="#id/bottom_sheet_header"
android:background="#color/color_white"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
This is the fragment that I put in the viewPager
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_own_product_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/profile_bg"
tools:context="fyp.hkust.facet.fragment.OwnProductFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/ownproductlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:padding="5dp">
</android.support.v7.widget.RecyclerView>
<com.melnykov.fab.FloatingActionButton
android:id="#+id/add_product_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:elevation="6dp"
android:src="#mipmap/ic_plus_white_36dp"
fab:fab_colorNormal="#color/colorPrimary"
fab:fab_colorPressed="#color/primary_pressed"
fab:fab_colorRipple="#color/ripple"
fab:fab_shadow="true" />
The following is the activity
Updated:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/profile_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<!-- your content layout -->
<LinearLayout
android:id="#+id/profile_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:elevation="0dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/profile_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/profile_bg"
tools:context="fyp.hkust.facet.activity.ProfileActivity">
<RelativeLayout
android:id="#+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:weightSum="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_picture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="25dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="25dp"
android:elevation="6dp"
android:src="#mipmap/app_icon" />
<Button
android:id="#+id/btn_edit"
android:layout_width="60dp"
android:layout_height="35dp"
android:layout_alignBottom="#+id/profile_email"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:adjustViewBounds="true"
android:background="#drawable/border_button_no_bg"
android:clickable="true"
android:contextClickable="true"
android:scaleType="fitCenter"
android:text="#string/edit_btn_text"
android:textColor="#color/font_color_pirmary" />
<TextView
android:id="#+id/profile_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="47dp"
android:layout_toEndOf="#+id/profile_picture"
android:layout_toStartOf="#+id/btn_edit"
android:text="#string/profile_username"
android:textSize="12sp" />
<TextView
android:id="#+id/profile_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_username"
android:layout_toEndOf="#+id/profile_picture"
android:layout_toStartOf="#+id/btn_edit"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:text="#string/profile_email"
android:textColor="#color/profile_email_text_color"
android:textSize="10sp" />
</RelativeLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:background="#color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:tabGravity="fill"
app:tabIndicatorColor="#color/white"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/grey_title" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tabs"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
How can I make it to let me scroll the whole view instead of scrolling only in the recycler view like instragram? Thank you.
Use NestedScrollview
Instead of scrollview.
You can enable / disable recyclerview's nested scrolling feature according to you need.
Scroll view doesn't support nested scrolling. Where as nested scroll view will give you what you need.
You should try following this hierarchy
<?xml version="1.0" encoding="utf-8"?>
<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/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="192dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
app:contentScrim="#color/action_bar"
app:expandedTitleGravity="right"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:id="#+id/app_images_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
app:layout_collapseMode="parallax">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="below will be your elements" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/accent"
app:tabGravity="fill"
app:tabIndicatorHeight="2dp"
app:tabMode="fixed" />
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Change this ,at the end of the xml layout close the ScrollView .Place it below the Relative layout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/profile_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/activity_profile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/profile_bg"
tools:context="fyp.hkust.facet.activity.ProfileActivity">
<RelativeLayout
android:id="#+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical"
android:weightSum="1">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_picture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="25dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="25dp"
android:elevation="6dp"
android:src="#mipmap/app_icon" />
<Button
android:id="#+id/btn_edit"
android:layout_width="60dp"
android:layout_height="35dp"
android:layout_alignBottom="#+id/profile_email"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="20dp"
android:adjustViewBounds="true"
android:background="#drawable/border_button_no_bg"
android:clickable="true"
android:contextClickable="true"
android:scaleType="fitCenter"
android:text="#string/edit_btn_text"
android:textColor="#color/font_color_pirmary" />
<TextView
android:id="#+id/profile_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="47dp"
android:layout_toEndOf="#+id/profile_picture"
android:layout_toStartOf="#+id/btn_edit"
android:text="#string/profile_username"
android:textSize="12sp" />
<TextView
android:id="#+id/profile_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_username"
android:layout_toEndOf="#+id/profile_picture"
android:layout_toStartOf="#+id/btn_edit"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:text="#string/profile_email"
android:textColor="#color/profile_email_text_color"
android:textSize="10sp" />
</RelativeLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:background="#color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:tabGravity="fill"
app:tabIndicatorColor="#color/white"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/grey_title" />
<LinearLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tabs"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
I am trying to collapse the custom toolbar with below code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ll_custom_toolbar_normal"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_toolbar_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/padding_16" />
<com.idolbee.android.customview.CustomTextView
android:id="#+id/tv_toolbar_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#android:color/white"
custom:font="ars_maquette_pro_bold"
tools:text="Title" />
<ImageView
android:id="#+id/iv_toolbar_menu1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/padding_16"
android:paddingLeft="#dimen/padding_16"
android:paddingTop="#dimen/padding_16"
android:visibility="gone" />
<ImageView
android:id="#+id/iv_toolbar_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/padding_16" />
</LinearLayout>
<ImageView
android:id="#+id/iv_my_stats_profile_pic"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginTop="#dimen/padding_16"
android:src="#drawable/profile_pic_holder" />
<com.idolbee.android.customview.CustomTextView
android:id="#+id/tv_my_stats_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/margin_16"
android:layout_marginTop="#dimen/margin_16"
custom:font="ars_maquette_pro_bold"
tools:text="Isabel Lozano" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.design.widget.TabLayout
android:id="#+id/tl_my_stats"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="#color/colorAccent"
app:layout_collapseMode="pin"
custom:tabBackground="#color/colorAccent"
custom:tabIndicatorColor="#color/colorPrimary"
custom:tabMode="scrollable"
custom:tabSelectedTextColor="#color/colorPrimary"
custom:tabTextColor="#color/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_my_stats"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:listitem="#layout/list_item_my_stats" />
<RelativeLayout
android:id="#+id/rl_fab_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/actionbar_overlay"
android:visibility="gone">
<LinearLayout
android:id="#+id/ll_home_fab_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="#dimen/margin_floating_action_menu"
android:layout_marginRight="#dimen/margin_16"
android:gravity="right"
android:orientation="vertical">
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/fab_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="#dimen/margin_16"
android:src="#drawable/floating_btn_menu" />
</android.support.design.widget.CoordinatorLayout>
But its not working. ToolBar is not collapsing with scroll event of RecyclerView.
Can anyone help me with this ?
Just remove exitUntilCollapsed from app:layout_scrollFlags and the CollapsingToolBar will start working.
PS: Tested