AppCompat v21 Dark ToolBar style

社会主义新天地 提交于 2019-12-03 07:46:03

问题


I want my ToolBar to serve as an ActionBar and I want it to look like a light theme with a dark action bar. I can't seem to find the right combination to do it.

This is what I have in styles.xml

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    <item name="windowActionBar">false</item>

    <item name="colorPrimary">@color/my_awesome_color</item>
    <item name="android:textColorPrimary">@color/my_awesome_text_color</item>
    <item name="colorPrimaryDark">@color/my_awesome_darker_color</item>
    <item name="colorAccent">@color/accent</item>

</style> 

And My toolbar

 <android.support.v7.widget.Toolbar
    android:id="@+id/my_awesome_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize" />

Currently I get this

What I want is that the menu items be white as well

Is there an elegant solution or do I have to choose a custom style for each one of the toolbar's items? It seems there should be.


回答1:


You can use the following theme on your Toolbar to get it to appear "dark". The first portion app:theme themes the color of the text on Toolbar to be light among other things. The app:popupTheme is for styling the overflow menu indicator to be light.

<android.support.v7.widget.Toolbar
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="@dimen/triple_height_toolbar"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />



回答2:


I am sure am a bit late but to do that in your theme add:

<item name="android:textColorSecondary">my_awesome_text_color</item>



来源:https://stackoverflow.com/questions/26531469/appcompat-v21-dark-toolbar-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!