上下文
使用AppCompat V7 21.0.0 / 21.0.2 / 21.0.3
Using the AppCompat v7 21.0.0 / 21.0.2 / 21.0.3
问题
工具栏的popupTheme并不适用于ShareAction
The popupTheme of the ToolBar is not applied to the 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>
溢出菜单项使用popupTheme正确
The overflow menu item is using the popupTheme properly
另一方面的ShareAction不接收popupTheme。经过一些测试,我注意到它收到的应用程序:工具栏因此是黑暗的主题
The ShareAction on the other hand does not receive the popupTheme. After some testing I noticed it received the app:theme of the ToolBar thus being dark.
<item name="android:colorBackground">@color/white</item>
为了得到对我试着设置很多属性ShareAction的黑色文字和设置安卓textColorPrimary(在工具栏的主题),我得到了我想要的,但当时我的图标上的工具栏也需要这种颜色是奇怪...
In order to get the black text on the ShareAction I tried setting many attributes and by setting "android:textColorPrimary" (on the ToolBar theme) I get what I want BUT then my icons on the ToolBar also takes this color which is weird...
菜单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>
我希望无论是ShareAction和放大器;溢出有popupTheme,但它并非如此。
I would expect both the ShareAction & the overflow to have the popupTheme but it's not the case
解决方法
我会编辑这篇文章,一旦我得到了解决办法
I'll edit this post once I got a workaround
编号:https://$c$c.google.com/p/android/issues/detail?id=87285&thanks=87285&ts=1419254842
所以,这里是为我工作。 这是我的工具栏的xml:
So, here's what worked for me. Here's my Toolbar xml:
<?xml version="1.0" encoding="utf-8"?>
<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/action_bar_main"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
app:theme="@style/Toolbar"
app:popupTheme="@style/Toolbar_Popup"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
请注意,我同时设置主题和popupTheme,我也超越背景是colorPrimary。 下面是主要的应用程序的主题描述与主题工具栏:
Notice that I set both theme and popupTheme, and I also override background to be colorPrimary. Here's the main app theme description with themes for Toolbar:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionMenuTextColor">@color/white</item>
<!-- Support library compatibility -->
<item name="actionMenuTextColor">@color/white</item>
<item name="actionBarSize">@dimen/actionbar_height</item>
<item name="colorPrimary">@color/dark_blue</item>
<item name="colorPrimaryDark">@color/dark_blue</item>
<item name="android:textColorPrimary">#607d8b</item>
</style>
<style name="Toolbar" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#fff</item>
<item name="android:background">@color/dark_blue</item>
</style>
<style name="Toolbar_Popup" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#fff</item>
<item name="android:background">@color/dark_blue</item>
</style>
所以,作为结果,共享操作的背景设置为背景的主工具栏主题的价值。和工具栏本身的背景是覆盖。
So, as a result, Share action background is set to the value of background in the main Toolbar theme. And the background of Toolbar itself is overriden.
上一篇:Application.SetCompatibleTextRenderingDefault(假);Application、SetCompatibleTextRenderingDefault
下一篇:的ImageButton选择XML文件没有在Eclipse 3.6.1发现了什么?发现了、文件、XML、ImageButton