【问题标题】:Modifying style does not work well修改样式效果不佳
【发布时间】:2014-04-19 08:01:30
【问题描述】:

我正在将应用的 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>

是否缺少任何物品?提前致谢

【问题讨论】:

  • 浅蓝色边框的蓝色渐变drawable是你的吗?
  • @RickFalck 不,它是从父级继承的。
  • 那么,你需要找出正在使用它的样式属性并覆盖它吗?
  • @RickFalck 是的,这就是我需要的。

标签: android android-actionbar android-ui android-appcompat


【解决方案1】:

我终于自己动手了。我不得不补充:

<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 的 style_base.xml(值和值-v14)中的 android:popupBackground 更改为 @drawable/menu_dropdown_panel_realestate。 AppCompat.Base.ListPopupWindow

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

【讨论】:

  • 我尝试了你的建议,但选项菜单的背景没有改变我使用了 ListPopupWindow
【解决方案2】:

我想我可以帮助您解决姜饼问题。 该菜单在 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文件中获取以下资源,并且将它们放在您的可绘制文件夹中。

具体来说:

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 Action Bar Generator)

【讨论】:

    【解决方案3】:

    稍后,它可能会有所帮助。在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-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 2014-08-31
      • 1970-01-01
      相关资源
      最近更新 更多