gpt4 book ai didi

Android:选择ListView后保持蓝色背景

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:08:40 27 4
gpt4 key购买 nike

我有一个 ListView,它在手机上运行良好。现在我正在制作一个平板电脑 UI,左侧是 ListView,右侧是详细信息。

当我触摸一个项目时,只要按下它就会闪烁蓝色。我想在选择另一个项目之前一直保持蓝色,就像 Nexus 7 上的 Gmail 应用程序一样。

实现该目标的最简洁方法是什么?我宁愿避免手动设置背景,我假设有一种方法可以将元素标记为“Activity ”元素并相应地设置主题。

最佳答案

What is the cleanest way to achieve that?

您正在寻找的是所谓的“激活”状态。为了使这项工作:

第 1 步:在 res/values-v11/ 中,有一个实现 activated 的样式资源。例如,对于一个在那里定义了 AppTheme 声明的新项目,使用如下内容:

<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light"></style>

<style name="activated" parent="AppTheme">
<item name="android:background">?android:attr/activatedBackgroundIndicator</item>
</style>

</resources>

第 2 步:在 res/values/ 中为任何旧设备定义相同的样式,就像 stub 样式资源一样,因此对它的引用可以继续工作:

<resources>

<style name="AppTheme" parent="android:Theme.Light"/>

<style name="activated" parent="AppTheme"/>

</resources>

第 3 步:在 ListView 中行的布局 XML 资源中,将 style="@style/activated" 添加到根的属性列表中元素

第 4 步:将 ListView 设置为单选列表,例如 ListFragment 中的以下行:

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);

您可以在 this sample project 中看到实际效果, this sample project , 和 this sample project .有关前两个示例的更多背景信息,请参阅此 SO 问题:Complete Working Sample of the Gmail Three-Fragment Animation Scenario?

关于Android:选择ListView后保持蓝色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12386333/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com