上下文
使用AppCompat v7 21.0.0/21.0.2/21.0.3
问题
ToolBar的popupTheme不适用于ShareAction
工具栏上的样式:
<style name="MyActionBarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/green</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Run Code Online (Sandbox Code Playgroud)
溢出菜单项正在使用popupTheme

另一方面,ShareAction没有收到popupTheme.经过一些测试后,我注意到它收到了应用程序:ToolBar的主题因此是黑暗的.
<item name="android:colorBackground">@color/white</item>
Run Code Online (Sandbox Code Playgroud)

为了获得ShareAction上的黑色文本,我尝试设置了许多属性,并通过设置"android:textColorPrimary"(在ToolBar主题上)我得到了我想要的但是我在ToolBar上的图标也采用了这种奇怪的颜色. .
菜单xml如下:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cycle="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/ic_share"
android:icon="@drawable/abc_ic_menu_share_holo_dark"
android:title="@string/media_share"
cycle:showAsAction="ifRoom"
cycle:actionProviderClass="android.support.v7.widget.ShareActionProvider" />
<item
android:icon="@drawable/abc_ic_menu_share_holo_dark"
android:showAsAction="ifRoom"
android:title="br">
<menu>
<item
android:id="@+id/menuSortNewest"
android:title="Sort by newest" />
<item
android:id="@+id/menuSortRating"
android:title="Sort by rating" />
</menu>
</item>
</menu>
Run Code Online (Sandbox Code Playgroud)
我希望ShareAction和溢出都有popupTheme但事实并非如此
解决方法
我得到一个解决方法后,我会编辑这篇文章
参考:https://code.google.com/p/android/issues/detail? id = 87285 & thanks = 87285 & t = 1419254842
有没有办法制作新的Android支持工具栏:
android.support.v7.widget.Toolbar
Run Code Online (Sandbox Code Playgroud)
有透明的背景吗?
我尝试将其设置colorPrimary为ARGB(#00ffffff),但它只是给了我一个坚实的灰色条.并且Toolbar只允许我设置背景可绘制.是否可以将背景绘制为透明PNG,或者有更好的方法吗?
理想情况下,我可以在代码/动画中执行它,以便某些活动具有透明条,而某些活动则没有.
提前致谢.
当我在我的应用程序中打开溢出菜单时,我看到菜单背景颜色的实心矩形显示在菜单本身的整个进入/退出动画中.这是一个动画显示这个(减速到75%的速度):

这个无关的彩色矩形的存在破坏了漂亮的进/出动画!如何在保留所有其他Toolbar样式的同时将其删除?
研究
我已经阅读了Toolbar关于SO的样式的一堆答案,以及Chris Banes关于这个主题的自己的帖子.似乎在过去的几年里,每个基础上的style/ theme标签的使用View都发生了变化,这使得很难在任何地方找到确定的信息.
我使用支持库的22.1.0到23.2.0(包括)版本重现了这一点.
应用文件
styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="ToolbarStyle" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/colorPrimary</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:style="@style/ToolbarStyle" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
运行时视图分析
正如@Commonsware 建议的那样,我在运行时查看了视图层次结构.在结果中编辑:
菜单折叠(存在溢出按钮,没有神秘的额外矩形):
菜单已展开(溢出菜单视图单独显示Window):
Window当比较两个菜单(稳定)状态时,主应用程序视图层次结构(如原始显示)保持不变.因此我的猜测是,在菜单动画期间,额外的矩形会临时添加到主应用程序的窗口中,并在完成后立即删除.我不确定为什么会这样做 - 也许这是一个显示和隐藏溢出菜单的旧(现在未使用)方法的宿醉?如果我的推论是正确的,那么如果我们能够确定如何防止这种短暂的行为,那么这个问题就可以得到解决......
在我的工具栏背景颜色中添加一些alpha时,我注意到标题的TextView有一个背景:
这是我的布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#0099cc">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="@style/FullscreenActionBarStyle"
app:titleTextAppearance="@style/ActionBarTitle"/>
<ImageView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我的styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
</style>
<style name="FullscreenTheme" parent="AppTheme">
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<!--For compatibility-->
<item name="actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
<item name="background">@color/black_overlay</item>
<item name="android:background">@color/black_overlay</item>
</style>
<style name="ActionBarTitle" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item …Run Code Online (Sandbox Code Playgroud)