Matias
Matias

Reputation: 1

AppBar color and tabbed menu

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

Upvotes: 0

Views: 111

Answers (1)

ORY
ORY

Reputation: 413

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

Upvotes: 0

Related Questions