Reputation: 4982
I use theme
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
But for CoordinatorLayour I need custom toolbar, not most-top-element (most top will be collapsing layout), so I use following style for Activity:
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And toolbar in activity.xml
<android.support.v7.widget.Toolbar
android:id="@+id/ac_main_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
tools:title="title"
app:theme="@style/AppTheme"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:layout_collapseMode="pin"/>
But it does not populated with colors from AppTheme. And looks like this
Why? I need my theme colors and dots at the center of toolbar.
Upvotes: 0
Views: 565
Reputation: 4982
After some research I found, that toolbar theme is not AppCompat theme and sould be ThemeOverlay.*
For dark action bar theme I should use
<style name="BarTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
not from parent="Theme.AppCompat.Light.DarkActionBar"
This fixes all color problems.
To fix title and 3 dots (put it in the middle of toolbar) - AppBarLayout height should be wrap_content (was fixed size before), and collapsing size in pixels should be moved to CollapsingToolbarLayout under AppBarLayout.
Upvotes: 1
Reputation: 500
Add following to your theme :
<!-- toolbar title and overflow menu color -->
<item name="android:textColorSecondary">@color/white</item>
And for the vertically center align you have to use height of toolbar as following :
<android.support.v7.widget.Toolbar
android:id="@+id/ac_main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" <!-- Height change -->
tools:title="title"
app:theme="@style/AppTheme"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:layout_collapseMode="pin"/>
Upvotes: 0
Reputation: 77
try to add android:background="@color/primary" to your toolbar definiton. Like:
android.support.v7.widget.Toolbar
android:id="@+id/ac_main_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_height"
android:background="@color/primary"
tools:title="title"
app:theme="@style/AppTheme"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:layout_collapseMode="pin"/>
Upvotes: 0