Change Toolbar color in Appcompat 21

again this is all in the link you supplied to change the text to white all you have to do is change the theme. use this theme <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/activity_my_toolbar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:minHeight=”?attr/actionBarSize” android:background=”?attr/colorPrimary” app:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light”/>

Use Tab with new ToolBar (AppCompat v7-21)

With the API 21 the method setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) is deprecated. UPDATE 01/08/2019 (Material Components Library) Add the dependency to your build.gradle: dependencies { implementation ‘com.google.android.material:material:1.1.0’ } Then you can use the new TabLayout. <androidx.constraintlayout.widget.ConstraintLayout> <com.google.android.material.appbar.AppBarLayout …> <androidx.appcompat.widget.Toolbar …/> <com.google.android.material.tabs.TabLayout … /> </com.google.android.material.appbar.AppBarLayout> <androidx.viewpager.widget.ViewPager android:id=”@+id/viewpager” app:layout_behavior=”@string/appbar_scrolling_view_behavior” /> </androidx.constraintlayout.widget.ConstraintLayout> The code is simple: TabLayout tabs = (TabLayout) findViewById(R.id.tabs); … Read more

Creating a Preference Screen with support (v21) Toolbar

Please find the GitHub Repo: Here A bit late to the party, but this is my solution that I am using as a work around continuing to use PreferenceActivity: settings_toolbar.xml : <?xml version=”1.0″ encoding=”utf-8″?> <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/toolbar” app:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:minHeight=”?attr/actionBarSize” app:navigationContentDescription=”@string/abc_action_bar_up_description” android:background=”?attr/colorPrimary” app:navigationIcon=”?attr/homeAsUpIndicator” app:title=”@string/action_settings” /> SettingsActivity.java : public class SettingsActivity extends PreferenceActivity { … Read more

Android 4.3 menu item showAsAction=”always” ignored

Probably you are missing required namespace: <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:[yourapp]=”http://schemas.android.com/apk/res-auto”> <item android:id=”@+id/menu_add_size” android:title=”@string/menu_add_item” android:orderInCategory=”10″ [yourapp]:showAsAction=”always” android:icon=”@android:drawable/ic_menu_add” /> </menu> Replace [yourapp] with your app name or any namespace your heart desires everywhere. Other things worth checking: See if your activity class extends ActionBarActivity Check if the issue persists. Android reference documentation: Adding Action Buttons. Here is the … Read more

Actionbar not shown with AppCompat

Use the compat name space for your menu items like this: <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:compat=”http://schemas.android.com/apk/res-auto” > <item android:id=”@+id/action_whatever” android:icon=”@drawable/ic_action_whatever” android:title=”@string/whatever” compat:showAsAction=”ifRoom” /> </menu>

Can’t Find Theme.AppCompat.Light for New Android ActionBar Support

You need to do next: File->Import (android-sdk\extras\android\support\v7). Choose “AppCompat” Project-> properties->Android. In the section library “Add” and choose “AppCompat” That is all! Note: if you are using “android:showAsAction” in menu item, you need to change prefix android as in the example http://developer.android.com/guide/topics/ui/actionbar.html

Display Back Arrow on Toolbar

If you are using an ActionBarActivity then you can tell Android to use the Toolbar as the ActionBar like so: Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); And then calls to getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); will work. You can also use that in Fragments that are attached to ActionBarActivities you can use it like this: ((ActionBarActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); ((ActionBarActivity) … Read more

Android: remove left margin from actionbar’s custom layout

If you are adding the Toolbar via XML, you can simply add XML attributes to remove content insets. <android.support.v7.widget.Toolbar xmlns:app=”schemas.android.com/apk/res-auto” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@color/primaryColor” android:contentInsetLeft=”0dp” android:contentInsetStart=”0dp” app:contentInsetLeft=”0dp” app:contentInsetStart=”0dp” android:contentInsetRight=”0dp” android:contentInsetEnd=”0dp” app:contentInsetRight=”0dp” app:contentInsetEnd=”0dp” />