嗨,谢谢您的阅读。

我的Android应用程序抽屉导航有问题,我无法将颜色从蓝色更改-我已经遍历了SO的所有其他问题,请参阅android文档,并且到目前为止已经尝试了所有方法……但是仍然没有运气。我真的希望有人能提供帮助。

到目前为止的代码:

my_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Blue still showing up! -->
    <item android:state_activated="true" android:drawable="@color/lightPink" />
    <item android:state_selected="true" android:drawable="@color/lightPink" />
    <item android:state_pressed="true" android:drawable="@color/lightPink" />
    <item android:state_focused="true" android:drawable="@color/lightPink" />
    <item android:drawable="@color/lightPink" />

</selector>

styles.xml
<item name="android:activatedBackgroundIndicator">@drawable/my_background</item>

fragment_navigation_drawer.xml
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:listSelector="@drawable/my_background"
    tools:context="com.randompractice.app.NavigationDrawerFragment"

/>

我已经坚持了24小时,这让我发疯。出于好奇,我好奇地告诉我要实现,但是却变成了一个愚蠢的小变化,变成了一个研究项目。有人可以看到我在做什么吗?

最佳答案

首先,我会尝试删除android:listSelector属性,因为我认为这不是必需的。

接下来,我将再次检查您是否具有所有这些步骤:

  • 在应用程序的主题中,尝试添加

  • themes.xml
    <style name="Theme.mytheme" parent="android:Theme.Holo">
        <item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
    </style>
    
  • 可绘制对象应该引用一个包含选择器的文件,例如

  • Activated_background.xml
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@color/my_color" android:state_activated="true" />
        <item android:drawable="@android:color/transparent" />
    </selector>
    

    colors.xml
    <resources>
        <item name="my_color" type="color">#ff0000</item>
    </resources>
    
  • 最后,确保使用
  • 将主题应用到 list 的application标签中

    AndroidManifest.xml
    android:theme="@style/Theme.mytheme"
    

    关于android - 将抽屉导航的选定项目颜色从默认蓝色更改为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23895941/

    10-12 00:23
    查看更多