0

I couldn't get help from any of the previous questions/answers, been trying this around for a whole lot now. So the problem is that I can't seem to change the color of the navigation tab (tabbed view) correctly. I am using API 21 with support repos.

If I use

ColorDrawable cd = new ColorDrawable(getResources().getColor(R.color.appbar));
actionBar.setBackgroundDrawable(cd);

It only colors the appbar-part, which is the top part of the whole top menu bar.

If I use

actionBar.setStackedBackgroundDrawable(cd);

it does color the tab-part, but at the same time it changes the top-parts background to light grey, regardless if I also call

actionBar.setBackgroundDrawable(cd);

or not. So below is a picture where are the 2 situations explained, and in the bottom a picture of what I'd like to have. Thanks!

Link to picture: https://onedrive.live.com/redir?resid=E71EFAAF41D1B253!9581&authkey=!AIj2vWVJIKIfVUo&v=3&ithint=photo%2cpng

Matias
  • 1

1 Answers1

0

Create a new Folder in "res" called values-v21with a styles.xml file in it.

<resources>
  <!-- inherit from the material theme -->
  <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
    <!-- Main theme colors -->
    <!--   your app branding color for the app bar -->
    <item name="android:colorPrimary">@color/primary</item>
    <!--   darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!--   theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
    
    <item name="android:alertDialogTheme">@style/Theme.AlertDialog</item>
    
    <item name="android:navigationBarColor">@color/primary</item>
  </style>
  
  <style name="Theme.AlertDialog" parent="Theme.AppCompat.Light.Dialog">

    <!--app abar color in Activties Task manager -->
    <item name="colorPrimary">@color/primary</item>

    <!--copy/paste colors -->
    <item name="colorAccent">@color/primary</item>

    <!--status bar color -->
    <item name="colorPrimaryDark">@color/primary</item>


</style>
  
  
</resources>

PrimaryDark is for the TitleBar and Primary is for Actionbar

ORY
  • 393
  • 1
  • 4
  • 11
  • If I don't use an AppCompat theme, the app will crash. Also if I use .NoActionBar it will crash when entering tabbed view. So I used Theme.AppCompat.Light as parent and it runs. The navigation and statusbar colors did change, but the tabs still remain the same light grey :\ – Matias Sep 18 '15 at 14:11
  • Have you tried this – ORY Sep 18 '15 at 14:15
  • Doesn't work :\ I wonder why the colors aren't applied at all for the appbar if I don't use actionBar.setBackgroundDrawable... The activities are using AppTheme and API 21. This is frustrating. – Matias Sep 18 '15 at 14:55