Setting Android Toolbar Background and Text Colors in Android Studio 1.4.1

I’m trying to change activity action bar’s background color and title color, i tried official tutorial and some answers from here but none worked for me , i’m missing something.

styles.xml

  • Android NDK - does it support straight ARM code or just Thumb
  • Failure when trying to install android apk package using adb for platform 4.1
  • Fragment saveInstanceState is coming as null after orientation change
  • Can Not Increase Android Emulator Internal Storage
  • Set rowSpan or colSpan of a child of a GridLayout programmatically?
  • Starting Android service already running?
  • <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
    

    styles.xml (v21)

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>
    

    MainActivity :

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        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" android:layout_width="match_parent"
        android:layout_height="match_parent" android:fitsSystemWindows="true"
        tools:context=".MainActivity">
    
        <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
            android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
    
            <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
                android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />
    
        </android.support.design.widget.AppBarLayout>
    
        <include layout="@layout/content_main" />
    
        <android.support.design.widget.FloatingActionButton android:id="@+id/fab"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
            android:src="@android:drawable/ic_dialog_email" />
    
    </android.support.design.widget.CoordinatorLayout>
    

    Related posts:

    How can I add a TextView to a LinearLayout dynamically in Android?
    Is there any disadvantage to using only high resolution image resources for an Android application?
    Android devices not having JIT
    KeyStore and Key Alias
    How can I limit fling in Android gallery to just one item per fling?
    Set layout_column and layout_row in GridLayout programmatically
  • System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found
  • How to update some data in a Listview without using notifyDataSetChanged()?
  • Are there any recommendations for request codes values in Android?
  • Android AlarmManager.setExactAndAllowWhileIdle() and WakefulBroadcastReceiver Not working in some new manufactured and low price devices
  • Creating a directory in /sdcard fails
  • run-as: Could not set capabilities: Operation not permitted
  • One Solution collect form web for “Setting Android Toolbar Background and Text Colors in Android Studio 1.4.1”

    So, if like me you are using Android Studio 1.4.1 and you are new to android programming, setting title and background colors can be done as follow :

    Background:(check colors.xml with this generated code for BlanckActivity)

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="colorPrimary">#3F51B5</color><!--Background color for AppBar-->
        <color name="colorPrimaryDark">#303F9F</color><!--i ignore its use-->
        <color name="colorAccent">#FF4081</color><!--color effects, EditText, RadioButtons...-->
    </resources>
    

    Title,Subtitle and popup menu and its items (check “styles.xml”) :

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
            <item name="android:textColorPrimary">TITLE_COLOR_GOES_HERE</item>
            <item name="android:textColorSecondary">SUBTITLE_COLOR_GOES_HERE</item>
    </style>
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light">
            <item name="android:colorBackground">MENU_POPUP_BACK_COLOR</item>
            <item name="android:textColor">@color/MENU_POPUP_ITEMS_COLOR</item>
    </style>
    

    Main Colors for an Activity

    I hope this can help someone who like me is confused in first steps provided with official android tutorials.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.