gpt4 book ai didi

android - 如何在 activatedBackgroundIndicator 中的选定/突出显示的列表项上设置自定义颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:47 24 4
gpt4 key购买 nike

您好,我正在使用 ActionBarSherlockNavigation Drawer 开发一个应用程序。我创建了一个带有 actionBar Sherlock 的初始抽屉导航,就像这样:

activatedBackgroundIndicator

一切似乎都很好但我想用我的自定义颜色更改突出显示的列表项的默认蓝色。我试过 this link但它不工作。我需要做什么才能实现自定义突出显示颜色?

最佳答案

您好,我已经通过应用样式解决了 Android 操作系统版本 11 及更高版本的问题:

<style name="AppBaseTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
</style>

drawable文件夹中的activated_background:

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
<item android:state_activated="true" android:drawable="@color/uva_color" />
<item android:state_selected="true" android:drawable="@color/uva_color" />
<item android:state_pressed="true" android:drawable="@color/uva_color" />
<item android:drawable="@color/default_color" />
</selector>

值文件夹中的颜色值:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="uva_color">#c31756</color>
<color name="default_color">#111</color>
</resources>

并在 ListView 中设置选择模式:

android:choiceMode="singleChoice"

最后,将 getBaseContext() 作为参数而不是 getApplicationContext() 发送到 arrayApdater/您的自定义适配器。

mMenuAdapter = new MenuListAdapter(this.getBaseContext(), title, icon);

还有 this link会帮助你。

如果您在任何地方遇到问题,请在下方发表评论。我随时准备回答,我不想让任何人像我一样遇到麻烦。干杯!

关于android - 如何在 activatedBackgroundIndicator 中的选定/突出显示的列表项上设置自定义颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17623961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com