nLL
nLL

Reputation: 5672

AppCompactv21 Toolbar as ActionBar theming has no affect

I have followed guide http://android-developers.blogspot.co.uk/2014/10/appcompat-v21-material-design-for-pre.html and implemented Toolbar as ActionBar but i cant seem to change theme of Toolbar. I am using Theme.AppCompat.Light as my app's base theme and would like to style/theme toolbar/actionbar individually.

Adding styles to my app_coomon_toolbar_xml has no affect at all For example when I add below

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"  

to app_common_toolbar.xml theme of it does not change and it still is picked from main app theme which is Theme.AppCompat.Light.

Only when I change App base theme to Theme.AppCompat.Light.DarkActionBar, Toolbar theme changes. I don't want to do that. What am I doing wrong?


Here are details of my my Toolbar and how I load it

app_common_toolbar.xml

    <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/app_common_toolbar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"    
/>

MainActivity.java super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.app_common_toolbar);

    if (toolbar != null) {
        setSupportActionBar(toolbar);
    }

Upvotes: 1

Views: 256

Answers (2)

nLL
nLL

Reputation: 5672

As per Pedro Oliveira's comments, I was doing null check for actionbar so, setSupportactionBar wasn't even called. I now able to make required changes by following his example on Github

Upvotes: 1

FrancescoAzzola
FrancescoAzzola

Reputation: 2654

I solved in this way:

<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/my_toolbar" android:layout_height="128dp" app:popupTheme="@style/ActionBarPopupThemeOverlay" android:layout_width="match_parent" android:background="?attr/colorPrimary" android:paddingLeft="72dp" android:paddingBottom="16dp" android:gravity="bottom" app:titleTextAppearance="@style/Toolbartitle" app:subtitleTextAppearance="@style/ToolbarSubtitle" app:theme="@style/ThemeOverlay.AppCompat.Light" android:title="@string/location_placeholder" />

and defined colors.xml like

    <resources>
      <color name="primaryColor_500">#03a9f4</color>
      <color name="primaryDarkColor_700">#0288d1</color>    
    </resources>

and finally style.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/primaryColor_500</item>
    <item name="colorPrimaryDark">@color/primaryDarkColor_700</item>
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

Hope this helps u!

Upvotes: 1

Related Questions