Smooth animated Collapsing Toolbar with Android Design Support Library

You can use the new layout_scrollFlag snap for smooth scroll within the AppBarLayout states. But what I have experienced is that, when the RecyclerView reaches top, scrolling stops. i.e CollapsingToolbarLayout won’t get expanded without another scroll. For the RecyclerView to scroll smoothly up and expand the CollapsingToolbarLayout I have used a ScrollListener on recyclerview. recyclerView.addOnScrollListener(new … Read more

onClick method not working properly after NestedScrollView scrolled

I found solution for same problem on this thread :The item inside RecyclerView can’t be clicked right after scrolling You can fix your code by adding layout_behavior to your AppBarLayout.You can find code here Fixed AppBarLayout.Behavior .Just add this class tou your project and fix your code : <android.support.design.widget.AppBarLayout android:layout_width=”match_parent” app:layout_behavior=”yourPackageName.FixAppBarLayoutBehavior” android:layout_height=”wrap_content”>

Android TabLayout Android Design

I’ve just managed to setup new TabLayout, so here are the quick steps to do this (ノ◕ヮ◕)ノ*:・゚✧ Add dependencies inside your build.gradle file: dependencies { compile ‘com.android.support:design:23.1.1’ } Add TabLayout inside your layout <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”?attr/colorPrimary”/> <android.support.design.widget.TabLayout android:id=”@+id/tab_layout” android:layout_width=”match_parent” android:layout_height=”wrap_content”/> <android.support.v4.view.ViewPager android:id=”@+id/pager” android:layout_width=”match_parent” android:layout_height=”match_parent”/> </LinearLayout> … Read more

how to remove left margin of Android Toolbar?

replace your xml with below xml <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:layout_alignParentTop=”true” android:background=”?attr/colorPrimary” android:elevation=”@dimen/margin_padding_8dp” android:contentInsetStart=”0dp” android:contentInsetLeft=”0dp” android:contentInsetRight=”0dp” android:contentInsetEnd=”0dp” app:contentInsetLeft=”0dp” app:contentInsetStart=”0dp” app:contentInsetRight=”0dp” app:contentInsetEnd=”0dp”> <RelativeLayout android:id=”@+id/rlToolbar” android:layout_width=”match_parent” android:layout_height=”match_parent”> <TextView android:id=”@+id/tvTitle” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_centerInParent=”true” android:paddingRight=”@dimen/margin_padding_16dp” android:text=”AppBar” android:textAppearance=”@style/TextAppearance.AppCompat” android:textColor=”@color/white” android:textSize=”@dimen/text_size_20sp” /> </RelativeLayout>

How to use a TabLayout with Toolbar inside CollapsingToolbarLayout?

Here’s the way I managed to do this, I don’t think that’s the best solution though if anyone finds a better way please feel free to post the answer. <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/main_content” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true”> <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.AppBarLayout android:id=”@+id/appbar” android:layout_width=”match_parent” android:layout_height=”@dimen/detail_backdrop_height” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” android:fitsSystemWindows=”true”> <android.support.design.widget.CollapsingToolbarLayout android:id=”@+id/collapsing_toolbar” android:layout_width=”match_parent” android:layout_height=”206dip” android:background=”@color/primary_dark” app:layout_scrollFlags=”scroll|exitUntilCollapsed” android:fitsSystemWindows=”true” … Read more

Dynamically add and remove tabs in TabLayout(material design) android

Remove tab from TabLayout … public void removeTab(int position) { if (mTabLayout.getTabCount() >= 1 && position<mTabLayout.getTabCount()) { mTabLayout.removeTabAt(position); mPagerAdapter.removeTabPage(position); } } … Add a removeTabPage method to your PagerAdapter … public void removeTabPage(int position) { if (!tabItems.isEmpty() && position<tabItems.size()) { tabItems.remove(position); notifyDataSetChanged(); } } … Add a Tab … private void addTab(String title) { mTabLayout.addTab(mTabLayout.newTab().setText(title)); … Read more

Don’t collapse Toolbar when RecyclerView fits the screen

Final Solution (thanks Michał Z.) Methods to turn off/on Toolbar scrolling: public void turnOffToolbarScrolling() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout); //turn off scrolling AppBarLayout.LayoutParams toolbarLayoutParams = (AppBarLayout.LayoutParams) mToolbar.getLayoutParams(); toolbarLayoutParams.setScrollFlags(0); mToolbar.setLayoutParams(toolbarLayoutParams); CoordinatorLayout.LayoutParams appBarLayoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams(); appBarLayoutParams.setBehavior(null); appBarLayout.setLayoutParams(appBarLayoutParams); } public void turnOnToolbarScrolling() { Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar); AppBarLayout appBarLayout = … Read more

Snackbar action text color not changing

The argument of setActionTextColor is the int that represents the color, not the resource ID. Instead of this: .setActionTextColor(R.color.yellow) try: .setActionTextColor(Color.YELLOW) If you want to use resources anyway, try: .setActionTextColor(ContextCompat.getColor(context, R.color.color_name)); Note: To use ContextCompat, I assume you have included Support library to your build.gradle file (It is optional if you have already appcompat (v7) … Read more