不断变化的抽屉式导航栏选择项目颜色从默认的蓝色 [英] Changing Navigation Drawer Selected Item Color from default blue

查看:181
本文介绍了不断变化的抽屉式导航栏选择项目颜色从默认的蓝色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,感谢阅读。

我有我的Andr​​oid应用导航抽屉一个问题,我无法从蓝色改变颜色 - 我已经去了来自因此,所有的其他问题,提到了Android的文件,并尝试了一切至今...但仍没有运气。我真的希望有人能够帮助。

I have a problem with my android apps navigation drawer where I cannot change the color from blue - I have went over all the other questions from SO, referred to the android documentation, and have tried everything so far... but still no luck. I really hope someone can help.

在code到目前为止:

The code so far:

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

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小时,现在,它是推动我疯了。对于这样一个愚蠢的变化不大,我的好奇心,告诉我实现,已经变成了一个研究项目。任何人都可以看到我在做什么错了?

I have been stuck on this for 24 hours now and it is driving me crazy. For such a silly little change that my curiosity told me to implement, has turned into a research project. Can anybody see what I am doing wrong?

推荐答案

首先,我会尝试删除了android:listSelector属性,因为我不认为有必要

First, I would try removing the android:listSelector attribute, as I don't believe it is necessary.

接下来,我会仔细检查你有所有这些步骤:

Next, I would double check you have all these steps:

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

的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>
    

    • 最后,请确保您使用的应用的主题在你的清单中的应用程序标记
    • AndroidManifest.xml中

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

      这篇关于不断变化的抽屉式导航栏选择项目颜色从默认的蓝色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆