CollapsingToolbarLayout setTitle() does not update unless collapsed

EDIT: This solution is no longer needed. bug fixed in v22.2.1 I didnt want to just leave links so here is the full solution. The bug occurs because the code to handle the collapsable title only updates the actual title if the current title is null or the text size has changed. The workaround is … Read more

Hide AppBar when scrolling down

Actually, that design seems to be wrong.Why? let me explain that to you. Except those xmlns:android=”http://schemas.android.com/apk/res/android” which it wasn’t necessary or using: android:layout_alignParentTop=”true” in the LinearLayout or using that ScrollView under the contents or etc, seems like you don’t have any idea what’s going on.(no problem). Note: the most important thing was, adding: app:layout_behavior=”@string/appbar_scrolling_view_behavior” which … Read more

How to add dividers between specific menu items?

You should use action layout <menu 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” tools:context=”.LandingActivity”> <item android:id=”@+id/action_cart” android:title=”cart” android:actionLayout=”@layout/cart_update_count” android:icon=”@drawable/shape_notification” app:showAsAction=”always”/> </menu> and then the action layout can have the textview with divider. <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”wrap_content” android:layout_height=”match_parent” android:orientation=”vertical”> <View android:id=”@+id/divider” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@drawable/divider”/> <TextView android:id=”@android:id/text” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”?android:attr/selectableItemBackground” android:gravity=”center_vertical” android:textAppearance=”?attr/textAppearanceListItemSmall”/> </LinearLayout> then you can add the click listener in code

Manage toolbar’s navigation and back button from fragment in android

Add a toolbar to your xml <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:theme=”@style/ThemeOverlay.AppCompat.ActionBar” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Fragment title”/> </android.support.v7.widget.Toolbar> Then inside your onCreateView method in the Fragment: Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_back_button); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().onBackPressed(); } });

Display ActionMode over Toolbar

Since you are using the Toolbar, I also assume you are using the AppCompatActivity and have replaced the built in ActionBar with your custom Toolbar using setSupportActionBar(toolbar); First of all ensure you are importing the correct namespace: import androidx.appcompat.view.ActionMode; // Or import android.support.v7.view.ActionMode; and NOT import android.view.ActionMode; then use _actionMode = startSupportActionMode(this); and NOT _actionMode … Read more

Evenly spaced menu items on Toolbar

Here’s what worked* for me: EnhancedMenuInflater.java import android.support.v4.internal.view.SupportMenuItem; import android.support.v7.internal.view.menu.MenuItemImpl; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import here.is.your.R; public class EnhancedMenuInflater { public static void inflate(MenuInflater inflater, Menu menu, boolean forceVisible) { inflater.inflate(R.menu.menu, menu); if (!forceVisible) { return; } int size = menu.size(); for (int i = 0; i < size; i++) { MenuItem item … Read more