2

我正在将我的应用程序的 UI 更改为绿色。在 ActionBar 中,我使用 ShareActionProvider 与其他用户共享数据,但此菜单项的颜色与其他菜单项不同。但是,它的下拉列表视图具有正确的颜色。

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

我在 GingerBread 中运行我的应用程序,所以当我按下菜单键时,会出现一个菜单项,但它的颜色也错误。

在此处输入图像描述

我使用过Android Action Bar Style Generator,但我缺少一些东西。这是我在 /res/values 中的代码:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarItemBackground">@drawable/selectable_background_newtheme</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.NewTheme</item>
    <item name="popupMenuStyle">@style/PopupMenu.NewTheme</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.NewTheme</item>
    <item name="actionDropDownStyle">@style/DropDownNav.NewTheme</item>

    <!-- Light.DarkActionBar specific -->
    <item name="actionBarWidgetTheme">@style/NewTheme.Widget</item>
</style>



<!-- ActionBar style -->
<style name="ActionBar.Solid.NewTheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/action_bar_gradient</item>
</style>

<style name="PopupMenu.NewTheme" parent="@style/Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">@drawable/background_gradient</item>
</style>

<style name="DropDownListView.NewTheme" parent="@style/Widget.AppCompat.ListView.DropDown">
    <item name="android:listSelector">@drawable/selectable_background_newtheme</item>
</style>

<style name="DropDownNav.NewTheme" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_newtheme</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_newtheme</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="NewTheme.Widget" parent="@style/Theme.AppCompat">
    <item name="popupMenuStyle">@style/PopupMenu.NewTheme</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.NewTheme</item>
</style>

有没有遗漏的物品?提前致谢

4

3 回答 3

3

我终于让它自己工作了。我不得不补充:

<item name="android:listChoiceBackgroundIndicator">@drawable/selectable_background_realestate</item>

在 *themes_base.xml* 中的 values-v14 和

<item name="listChoiceBackgroundIndicator">@drawable/selectable_background_realestate</item>

在 Themes_base.xml 中按下列表项时正确突出显示颜色的值。

我还必须更改theme_base.xml(值和值-v14)中的 actionBarItemBackground 以引用我的可绘制对象,以便共享图标获得相同的突出显示。

最后,为了获得下拉菜单项的正确颜色,我必须将Widget.AppCompat.Base.ListPopupWindow 的 styles_base.xml(值和值-v14)中的android:popupBackground更改为 @drawable/ menu_dropdown_panel_realestate

我在回答中引用的可绘制对象是使用Android Asset Studio for AppCompat生成的

于 2014-01-03T21:08:11.460 回答
0

稍后,它可能会有所帮助。在 GingerBread 中,当您按下菜单键时,底部出现的菜单项可以通过以下属性进行自定义itemBackground

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:itemBackground">@drawable/selectable_background_newtheme</item>
</style>  

然后,显然要自定义ShareActionProvider按下的项目,您需要此属性:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:selectableItemBackground">@drawable/selectable_background_newtheme</item>
</style>  
于 2014-04-17T22:25:11.173 回答
0

我想我可以帮你解决你的姜饼问题。该菜单在 AppCompat 样式和主题 .XML 文件中称为“面板” 。

所以要用你自己的选择器颜色覆盖它,这就是我的建议:

在您的自定义主题中CustomActionBarTheme,添加以下行:

    <item name="panelMenuListTheme">@style/Theme.NewTheme.CompactMenu</item>

并添加这两种样式:

<style name="Theme.NewTheme.CompactMenu" parent="@style/Theme.AppCompat.CompactMenu">
     <item name="android:listViewStyle">@style/myCustomMenuStyle</item>
</style>

<style name="myCustomMenuStyle" parent="@style/Widget.AppCompat.ListView.Menu">
    <item name="android:listSelector">@drawable/newtheme_list_selector_holo_light</item>
</style> 

注意:这@drawable/newtheme_list_selector_holo_light是我从Android Holo Colors Generator获得的 xml 资源。

我建议你使用网站,顺便说一下,在这种情况下你只需要“列表选择器”的资源,并从它输出的 ZIP 文件中获取以下资源,并将它们放在你的 drawable 文件夹中。

具体来说:

newtheme_list_selector_holo_light.xml > 在 res/drawable

newtheme_list_selector_background_transition_holo_light.xml > 在 res/drawable

以及以下 .9.png 资源的 mdpi、hdpi、xdpi 和 xxdpi:

newtheme_list_selector_disabled_holo_light.9.png

newtheme_list_pressed_holo_light.9.png(类似于创建的 png Action Bar Generator)

newtheme_list_longpressed_holo.9.png

newtheme_list_focused_holo.9.png(类似于创建的 png 动作栏生成器)

于 2013-12-31T21:20:29.190 回答