【发布时间】:2017-04-18 14:07:24
【问题描述】:
我正在使用自定义操作栏,因此我使用我的代码在 @drawable/menu/themes.xml 中创建了一个名为themes 的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#2d73c4</item>
</style>
</resources>
我还使用我的代码创建了一个 .xml 文件名操作栏,并将其放入 @drawable/menu/actionbar.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/search"
android:showAsAction="always"
android:title="Αναζήτηση"
android:icon="@drawable/ic_action_search"/>
</menu>
所以我希望当我使用列表视图时,在我选择的项目上更改颜色。 我在我的主题.xml 中尝试了这一行,但没有成功。
<item name="android:colorActivatedHighlight">@android:color/transparent</item>
【问题讨论】:
-
不能安静地理解你的问题,你有一个列表视图,当你选择一个项目时,你的操作栏应该改变它的颜色?哪种颜色?背景?
-
完全正确。直到现在当我选择项目时不会改变背景颜色。
-
您是否在应用中添加了
Toolbar小部件?你可以通过 id 找到它,并在后面的代码中设置它的背景颜色。