state_activated 在蜂窝设备之前 [英] state_activated on pre Honeycomb Devices

查看:29
本文介绍了state_activated 在蜂窝设备之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您不能使用以下状态可绘制作为列表视图项的背景.

You can not use the following state drawable as background for listview items.

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

在 Pre Honeycomb 设备上,因为那里不支持此选择器,并且 android 版本不跟踪激活的项目.

On Pre Honeycomb Devices because this selector is not supported there and the android version does not keep track of the activated item(s).

如何模拟这种行为?尤其是在使用片段时(在一个片段的左侧列出,根据选择的内容在右侧显示详细信息),这一指标非常重要.

How can this behaviour be emulated? Especially when using fragements (list on the left in one fragment and depending on what is selected a detail view on the right) this indicator is very important.

我知道这个问题是在这里之前被问到的,但在那里接受的答案指向博客文章的链接,该文章在第 4 步"中指出不可能有已激活的指标,而只能禁用使用以防止错误.这导致没有显示我正在搜索的指标.

I know that this question was asked before here but the accepted answer there links to a blog article which states in "Step 4" that there is no possibility to have the activated indicator and instead only disables the use to prevent errors. This leads to the fact that no indicator is displayed which is what I'm searching for.

推荐答案

我用一个小技巧解决了这个问题:通过误用 state_checked 属性,它存在于 Android 版本 1 中,有可能模拟 state_activated 行为.无需修改List适配器或自行保存状态.

I solved the problem using a small trick: By missusing the state_checked property, which exists since Android Version 1, it is possible to emulate the state_activated behaviour. There is no need to modify the List adapter or save the state yourself.

我编写了一个详细的示例,其中包含重新发布所需的所有代码,并将其发布在 github 存储库上.

I wrote a detailed example containing all code necessary to repoduce and published it on a github repository.

这篇关于state_activated 在蜂窝设备之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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