Android的列表选择用得到的时候Theme.Light卡住 [英] Android list selector gets stuck when using Theme.Light
问题描述
我有一个ListView和我使用Theme.Light为我的行为,但是当用户点击一个列表项我的名单选择器卡住,直到用户点击其他地方。当我使用默认的主题不会出现这种情况!
I have a ListView and I am using Theme.Light for my activity, but when the user taps a list item my list selector gets stuck until the user taps somewhere else. This does not happen when I use the default theme!
首先,我有这个问题:<一href=\"http://stackoverflow.com/questions/2183447/listselector-applies-to-the-entire-list\">ListSelector适用于整个列表,现在我已经打了另一个。谷歌,这是怎么回事那边?!
First I had this problem: ListSelector applies to the entire list and now I've hit another. Google, what is going on over there?!
推荐答案
这是一个pretty恼人的问题,对于一些原因可能你使用的是什么主题有关。我不知道的根本原因是什么,但在这里是一个已经为我工作一个解决方法(在Android平台本身present)。
This is a pretty annoying issue that for some reason might be related to what theme you are using. I'm not sure exactly what the root cause is, but here is a workaround (present in the Android platform itself) that has worked for me.
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
(从list_selector_background.xml取)
(taken from list_selector_background.xml)
注意,Android平台的开发者似乎也有碰到这个问题,他们有一种变通方法重新使用不同的选择状态相同的背景资源。显然,触发一个重新调用validate能解决问题(至少对我来说)。
Notice that the Android platform developers seemed to have also run into this problem, and they have a workaround that re-uses the same background resource for different selector states. Apparently that triggers an re-validate call that fixes the problem (at least for me).
这篇关于Android的列表选择用得到的时候Theme.Light卡住的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!