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(); } });

What is the Default ActionBar Title Font Size?

The short one… $ grep ActionBar platforms/android-11/data/res/values/* leads to styles.xml: <style name=”TextAppearance.Widget.ActionBar.Title” parent=”@android:style/TextAppearance.Medium”> </style> <style name=”TextAppearance.Widget.ActionBar.Subtitle” parent=”@android:style/TextAppearance.Small”> </style> […] <style name=”TextAppearance.Medium”> <item name=”android:textSize”>18sp</item> </style> <style name=”TextAppearance.Small”> <item name=”android:textSize”>14sp</item> <item name=”android:textColor”>?textColorSecondary</item> </style>

How do I open the SearchView programmatically?

Expand the SearchView with searchView.setIconified(false); and collapse it with searchView.setIconified(true); You need to change the value of android:showAsAction from ifRoom|collapseActionView to always. The SearchView‘s attribute android:iconifiedByDefault should be true, which is the default value, otherwise the user can not collapse the SearchView after it was expanded programmatically.

Change Android 5.0 Actionbar color

AppCompat does not use the android: prefixed attributes for the Material Theme color palette items per the migration guide to v21 by the author of AppCompat. Instead, just use the names themselves: <style name=”AppTheme” parent=”@style/Theme.AppCompat.Light.DarkActionBar”> <item name=”colorPrimary”>@color/primaryDef</item> <item name=”colorPrimaryDark”>@color/primaryDarkDef</item> <item name=”colorAccent”>@color/primaryDef</item> <item name=”android:navigationBarColor”>@color/primaryDarkDef</item> <item name=”android:activatedBackgroundIndicator”>@drawable/defbg</item> </style> The Action Bar will be colored by colorPrimary.

How change position of popup menu on android overflow button?

To overlap only, use this approach: PopupMenu popupMenu = new PopupMenu(getContext(), this, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0); To get a PopupMenu with a bright background and a detailed control over the offsets use this approach: styles.xml <style name=”PopupMenuOverlapAnchor” parent=”@style/Theme.AppCompat.Light”> <item name=”android:overlapAnchor”>true</item> <item name=”android:dropDownVerticalOffset”>0dp</item> <item name=”android:dropDownHorizontalOffset”>0dp</item> </style> Code: ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getContext(), R.style.PopupMenuOverlapAnchor); PopupMenu popupMenu = new … Read more