本文介绍了绘制对象选择不工作在果冻豆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绘制选择作为背景,在的ListView 每个项目要突出所选行。 Eveything工作正常的冰淇淋三明治,但似乎并没有在果冻豆的工作。无法找到任何文件说了什么变化可能会导致其停止工作,我需要做些什么来解决这个问题。

I have a drawable selector as a background for each item in a ListView to highlight the selected row. Eveything works fine in Ice Cream Sandwich, but doesn't seem to work in Jelly Bean. Can't find any documentation saying what changes could have caused it to stop working and what I need to do to fix it.

如果不工作,我的意思是,当我点击一个行中的的ListView 该项目的背景色是不转动 @色/蓝色的颜色,但它确实在ICS。

By not working, I mean when I click on a row in the ListView the item's background color isn't turning the @color/blue color, but it does in ICS.

这是选择code我使用(listing_selector.xml):

This is the selector code I'm using (listing_selector.xml):

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

   <item android:state_focused="true" android:drawable="@color/blue" />

   <item android:state_pressed="true" android:drawable="@color/blue" />

   <item android:state_activated="true" android:drawable="@color/blue_selected" />

   <item android:state_selected="true" android:drawable="@color/blue_selected" />

   <item android:drawable="@android:color/transparent" />

</selector>

这是 ListView控件的布局项目:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="@color/listing_selector"
>

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
    />

</RelativeLayout>

这蓝色资源:

<resources>
    <color name="blue">#ff33b5e5</color>
</resources>

更新1:

试图移动从颜色选择器文件夹复制到绘制文件夹和更新code本

Tried moving the selector from the color folder to the drawable folder and updating the code to this:

android:background="@drawable/listing_selector"

更新2:

此外,在的ListView ,尝试添加这样的:

Also, on the ListView, tried adding this:

    <ListView android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:listSelector="@drawable/listing_selector"
    />

更新3:

我想这可能是东西在我的code,但我删除了所有的code从 onListItemClick 的ListView ,目前仍是选择是行不通的。

I thought it might be something in my code, but I removed all the code from onListItemClick of the ListView and still the selector isn't working.

更新4:

我已经把范围缩小到 state_selected state_activated 不能正常工作, STATE_ pressed 似乎工作

I've narrowed it down to state_selected or state_activated not working as, state_pressed seems to be working

更新5:

我想我是错了。我不认为选择是被公认,在所有。我混淆了内置的的ListView 彰显我的选择。我现在想知道如果有事情做的方式我的项目设置。我有一个库类的选择。也许改变的东西与从ICS到JB,但是移动选择我的应用程序的项目似乎并没有解决这个问题。

I think I was mistaken. I don't think the selector is being recognized, at all. I was confusing the built-in ListView highlighting as my selector. I'm now wondering if it has something to do with the way my project is setup. I have the selector in a Library Class. Maybe something changed with that from ICS to JB, however moving the selector to my app's project didn't seem to fix it.

更新6:

好了,经过一番更揪头发,我已经将范围缩小,再一次,为 state_selected state_activated 不被认可,在更换颜色 STATE_ pressed 做的工作,这意味着我的选择是被公认。从评论中似乎有什么东西与我的应用程序专为其他人能够得到选择与果冻豆的工作。

Ok, after some more hair pulling, I've narrowed it down, again, to either state_selected or state_activated not being recognized, as changing the color for state_pressed does work, which means my selector is being recognized. From the comments in seems to be something with my app specifically as others have been able to get selectors working with Jelly Bean.

虽然这是有趣的别的东西是改变绘制值的默认状态是无法识别。在那里我有彩色/透明,我想改变这种以颜色会导致上市更改为颜色,但事实并非如此。

Though something else that is interesting is that changing the drawable value for the default state is not recognized. Where I have color/transparent, I would think changing that to a color would cause the listing to change to that color, but it doesn't.

此外,这是不工作的ICS无论是。

Also, this isn't working in ICS either.

更新7:

在更揪头发,我发现在一个菜单项导致该项目的颜色长期pressing被改变。只需点击一个项目仍然无法正常工作。甚至不知道这是什么意思。

After even more hair pulling, I've discovered that long-pressing on a menu item results in that item's color being changed. Just clicking on an item still does not work. Not even sure what the means.

**最后更新:**

** Final Update:**

我放弃了,我删除了选择和我刚刚刷新的ListView 上点击和记忆的位置单击,并从code突出显示。不理想,但不值得努力尝试解决。

I give up, I removed the selector and am just refreshing the ListView on click and remembering the position clicked and highlighting it from code. Not ideal, but not worth the effort to try to fix.

推荐答案

好吧,我觉得它的一个问题,你的选择。尝试取出state_focused和state_activated。你可以试试这个为你的选择:

Okay, i think its an issue with your selector. Try removing the state_focused and the state_activated. You could try this for your selector:

<!-- Disabled State -->
<item
    android:state_enabled = "false"
    android:state_focused = "true"
    android:state_pressed = "true"
    android:drawable="@android:color/transparent">
</item>
<item
    android:state_enabled = "false"
    android:state_focused = "true"
    android:drawable="@android:color/transparent">
</item>

<!-- Pressed State -->
<item
    android:state_pressed = "true"
    android:state_focused = "true">
    <shape>
        <solid android:color="@color/blue"/>
    </shape>
</item>
<item
    android:state_pressed = "true"
    android:state_focused = "false">
    <shape>
        <solid android:color="@color/blue"/>
    </shape>
</item>

<!-- Normal State -->
<item
    android:drawable="@android:color/transparent">
</item>

我发现我需要使用一个图形对象太多,而不是安卓绘制,因为pre-ICS电话,整个列表将被强调,颜色,而不是pressed列表项。

I found that I needed to use a shape object too instead of android:drawable, because on pre-ICS phones, the whole list will be highlighted that color instead of the pressed list item.

您可以在 state_selected $ C $将C过,但我不知道它如何被使用。退房的默认选择code果冻豆为他们所使用的规定:<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.1.1_r1/frameworks/base/core/res/res/drawable/list_selector_background.xml?av=f"相对=nofollow> list_selector_background.xml 。

You can add in your state_selected code too, but I'm not sure how it will be used. Check out the default selector code for jelly bean for the states they use: list_selector_background.xml.

这篇关于绘制对象选择不工作在果冻豆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 07:14