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

How to use TextInputLayout in new android design library

TextInputLayout extends ViewGroup class. So which means that you have to wrap your EditText in a TextInputLayout. <android.support.design.widget.TextInputLayout android:layout_width=”match_parent” android:layout_height=”wrap_content”> <EditText android:layout_width=”match_parent” android:layout_height=”wrap_content” android:hint=”hint” android:id=”@+id/editText1″ /> </android.support.design.widget.TextInputLayout>

How can I determine that CollapsingToolbar is collapsed?

As Marko said, this can be achieved using your own implementation of a OnOffsetChangedListener. AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.app_bar_layout); appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) { // Collapsed } else if (verticalOffset == 0) { // Expanded } else { // Somewhere in between } } … Read more

Android L – Floating Action Button (FAB)

UPDATED: 26/08/2021 With the Material components for android add to your build.gradle: implementation ‘com.google.android.material:material:1.x.x’ Then add in your layout: <com.google.android.material.floatingactionbutton.FloatingActionButton android:id=”@+id/floating_action_button” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_gravity=”bottom|right” android:layout_margin=”16dp” app:srcCompat=”@drawable/ic_plus_24″/> And use it: FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.floating_action_button); floatingActionButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { // Handle the click. } }); If you are using a Theme.MaterialComponents.* … Read more