actionBarItemBackground

actionBarItemBackground

本文介绍了动作条与AppCompat actionBarItemBackground不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图改变它时,pressed项目的颜色。我使用了 actionBarItemBackground 项目操作栏中的风格,但没有任何反应。该颜色没有改变...

I am trying to change the color of an item when it pressed. I used the actionBarItemBackground item in the action bar style, but nothing happens.. The color not changed...

下面我code:

<style name="ActionBarStyle" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="android:background">@color/actionbar_background</item>
    <item name="titleTextStyle">@style/ActionBarStyle.Title</item>
    <item name="actionBarItemBackground">@drawable/action_bar_item_selector</item>
    <item name="android:actionBarItemBackground" tools:ignore="NewApi">@drawable/action_bar_item_selector</item>
</style>

和选择:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/pressed_item" android:state_focused="true"/>
    <item android:drawable="@drawable/pressed_item" android:state_pressed="true"/>
    <item android:drawable="@android:color/transparent"/>

</selector>

和提拉:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <solid android:color="#FF0000"/>
</shape>

什么是worng?有人?

What is worng? Someone?

推荐答案

actionBarItemBackground 不继承 Widget.ActionBar 。你应该把它放在你的根的主题,无论你使用你的 ActionBarStyle ,但不是的的你的 ActionBarStyle 。所以,是这样的:

actionBarItemBackground isn't inherit of Widget.ActionBar. You should be placing it in your root theme, wherever you apply your ActionBarStyle, but not in your ActionBarStyle. So, something like:

<style name="Your.Theme" parent="@style/Theme.AppCompat">
    <item name="actionBarStyle">@style/ActionBarStyle</item>
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
    <item name="actionBarItemBackground">@drawable/action_bar_item_selector</item>
    <item name="android:actionBarItemBackground" tools:ignore="NewApi">@drawable/action_bar_item_selector</item>
</style>

这篇关于动作条与AppCompat actionBarItemBackground不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 04:30