android - 导航 View 的 itemTextColor 的颜色选择器

标签 android xml navigationview android-selector

我想在 itemTextColor 的导航 View 中放置一个文本颜色选择器:

导航 View :

<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="225dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/bleu"
        android:fitsSystemWindows="true"
        app:itemTextColor=""
        app:itemBackground="@drawable/item_background"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

我的选择器:

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

        <item android:state_pressed="true" android:drawable="@color/bleu" />
        <item android:state_focused="true" android:drawable="@color/bleu" />
        <item android:state_checked="true" android:drawable="@color/bleu" />

    </selector>

但是我不能在res/drawable中选择一个文件。我的选择器放在哪里?我在互联网上看到过 res/color/my_selector.xml,但它不起作用,因为它说我的选择器不允许出现在 res/color 的 xml 中。如果我将选择器放在 res/colors.xml 中,我不知道如何从 colors.xml 文件中选择它。

请告诉我该怎么做?

最佳答案

您可以直接从 NavigationView 上的 app:itemBackground 属性引用选择器

app:itemBackground="@drawable/my_selector"

这应该没问题

关于android - 导航 View 的 itemTextColor 的颜色选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36142921/

相关文章:

java - 单击按钮时数字增加

xml - JAX-B 能否逐字包含 XML 值属性?

xml - 如何分解 XSLT 中的大型 XPath?

android - 如何在 NavigationView 中添加其他布局

java - 找不到符号方法 findPreference(String)

java - Youtube Android API - callingAppVersion 不能为 null 或为空

android - Android Studio Kotlin:BitmapFactory.decodeStream()返回null

python - 在 Python 中从 XML 中提取数据

android - 如何为 NavigationView 中的项目设置自定义字体?

ios - ViewController 通过在屏幕上交换转到上一个 ViewController