抽屉式导航栏项目的背景颜色选择的项目 [英] Navigation Drawer item background colour for selected item

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

问题描述

我用Android的工作室来实现导航抽屉,我不能让蓝颜色是用来显示我们目前的哪个部分来改变。

I used Android Studio to implement the Navigation Drawer and I can't get the blue colour that is used to show which section we're currently in to change.

我试过很多东西,我目前使用的是listSelector它看起来像:

I've tried numerous things, I'm currently using a listSelector which looks like:

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

    <item android:state_activated="true" android:drawable="@color/selected" />
    <item android:state_pressed="true" android:drawable="@color/highlight" />


</selector>

我也试过 state_checked STATE_ pressed 工作在这种情况下,但当前选择的项目仍然是蓝色的。

I've also tried state_checked. state_pressed works in this situation but the currently selected item is still blue.

编辑: 我一直在研究这个更多,当适配器创建的传递是 getActionBar()的范围内。getThemedContext(),所以我如果我能找到合适的正在考虑属性分配给我的动作条的风格,我可以从那里更改。我试过没有运气的几个不同的属性。没有人知道确切的属性?

I've been examining this more and when the adapter is created the context that is passed is getActionBar().getThemedContext() so I'm thinking if I can find the right attribute to assign to my actionbar style I can change it from there. I've tried a few different attributes with no luck. Does anyone know the exact attribute?

我也意识到,如果我把

&LT;项目name="android:activatedBackgroundIndicator">@drawable/nav_listview_selector</item>

在我的主题和变化 getActionBar()的主要部分。getThemedContext() getActivity.getBaseContext 然后我可以改变颜色,但我不认为这是正确的方式。我觉得主题的背景下,应使用。因此,如果有人知道其中 activatedBackgroundIndicator 可以放在这样它会在使用getActionBar.getThemedContext()

in the main part of my theme and change getActionBar().getThemedContext() for getActivity.getBaseContext then I can change the color but I don't think this is the correct way. I think the themed context should be used. So if anyone knows where the activatedBackgroundIndicator could be put so that it would be used in getActionBar.getThemedContext()

EDIT2:

所以用于列表视图文本视图是在SDK中,它看起来是这样的:

So the text view used for the listview is one within the SDK it looks like this:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:background="?android:attr/activatedBackgroundIndicator"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
/>

所以,我试图修改机器人:ATTR / activatedBackgroundIndicator在主题的水平,但它有没有影响检查/选择/激活,但它为pressed。有谁知道这是为什么?我怎么可以改变它?

So I tried modifying the "?android:attr/activatedBackgroundIndicator" at the theme level but it has no effect for checked/selected/activated but it does for pressed. Does anyone know why this is? And how I can change it?

推荐答案

不过不知道为什么它是,它不能正常工作。但我发现它周围的方式是用我自己的 simple_list_item_activated 布局要传递给一个Ar​​rayAdapter这基本上除了文字颜色设置​​为白色相同。后来我换成 getActionBar()。getThemedContext() getActivity()。getBaseContext(),它现在有效果

Still not sure why it is that it doesn't work. But the way I found around it is to use my own simple_list_item_activated layout to be passed to the ArrayAdapter which was basically the same except for setting the text colour to white. I then replaced getActionBar().getThemedContext() with getActivity().getBaseContext() and it now has an effect.

这可能不是正确的方法,并可能在未来产生影响,但现在我有工作,我希望它的方式。

This may not be the correct way and may have repercussions in the future, but for now I have it working the way I want it to.

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

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