我正在测试新的Appcompat 21 Material Design功能.因此我创建了一个这样的工具栏:
<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/activity_my_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar"/>
Run Code Online (Sandbox Code Playgroud)
并将其包含在我的主布局文件中.
然后我将它设置为supportActionBar:
Toolbar toolBar = (Toolbar)findViewById(R.id.activity_my_toolbar);
setSupportActionBar(toolBar);
Run Code Online (Sandbox Code Playgroud)
它工作,但不知何故,我无法弄清楚如何自定义工具栏.它是灰色的,上面的文字是黑色的.我该如何更改背景和文字颜色?
我已经完成了这个指示:
http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html
我有什么要改变颜色的?
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowActionBar" tools:ignore="NewApi">false</item>
<item name="windowActionBar">false</item>
</style>
Run Code Online (Sandbox Code Playgroud)
编辑:
我可以通过在主题中添加以下代码行来更改背景颜色:
<item name="colorPrimary">@color/actionbar</item>
<item name="colorPrimaryDark">@color/actionbar_dark</item>
Run Code Online (Sandbox Code Playgroud)
但它们不会影响文字颜色.我错过了什么?我宁愿选择白色文字和白色菜单按钮,而不是黑色文字和黑色菜单按钮:

android android-appcompat android-actionbar android-actionbar-compat android-toolbar
我正在使用Android工具栏.我只想更改溢出菜单的背景颜色.但它并没有改变.
风格xml
<style name="MyDarkToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="popupTheme">@style/PopupMenuStyle</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
<style name="PopupMenuStyle" parent="android:Widget.Holo.Light.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
工具栏XML
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/ColorPrimary"
android:elevation="2dp"
android:theme="@style/MyDarkToolbarStyle" />
Run Code Online (Sandbox Code Playgroud) 我正在尝试将appcompat-v7工具栏设置为我的溢出菜单的不同背景颜色.我尝试使用我的应用程序的主题和我的工具栏的样式,但我无法实现它.
这是我的工具栏:
<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/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
app:theme="@style/AppToolbarTheme"
android:layout_height="wrap_content">
Run Code Online (Sandbox Code Playgroud)
这是我创建的风格:
<style name="AppToolbarTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/cian</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的主题是扩展Theme.AppCompat.Light.
有谁知道我该怎么做?如果不可能使用样式有没有其他方法来实现它?