gpt4 book ai didi

android - 旧设备上的全息快速滚动外观

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

关于我的应用

我有一个具有全息外观的应用程序。

对于 Honeycomb 之前的设备,我只是向后移植了 Holo 主题的一些元素。

可以使用主题、样式和属性来处理 CheckBox、RadioButton ...

我想做什么

我使用 ListView 来显示很多项目。我想在我的 ListView 上启用快速滚动,我希望它具有全息外观。

我的问题

我在将快速滚动 Drawable it 集成到我的应用主题中时遇到了一些困难。

到目前为止我尝试了什么

  1. 正在寻找执行此操作的库。HoloEverywhere 是有前途但不处理。

  2. 尝试自己做:

我刚刚添加了那些可绘制对象:

enter image description here enter image description here

然后还添加了这个drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/fastscroll_thumb_pressed_holo" />
<item android:drawable="@drawable/fastscroll_thumb_default_holo" />
</selector>

在我的 attrs.xml 中添加了这个:

<attr name="fastScrollThumbDrawable" format="reference" />

我在我的 themes.xml 中添加了这个:

<style name="MyTheme">
<item name="fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
</style>

此主题已在 Manifest.xml 中正确设置到我的应用:

android:theme="@style/MyTheme"

请记住 android:fastScrollThumbDrawable doesn't exist pre-honeycomb


我希望你能帮我解决这个问题。 :)

更新:

看来快速滚动支持已在几个小时前添加到 HoloEverywhere 中:

https://github.com/ChristopheVersieux/HoloEverywhere/commit/34561e48339bf6a3e0307d2d35fc4c5ac8409310

我会检查一下。 :)

最佳答案

我正在使用 android:fastScrollThumbDrawable 但我不知道为什么它不起作用,所以在网上搜索我发现 here一个硬代码解决方案,我不知道它是否可以像您需要的那样在旧 API 上运行,但就我而言,问题已解决。请注意,我正在使用 API 18 之类的目标和带有 API 17 的设备进行测试。

代码:

try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o = f.get(<<your listView here>>);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable = (Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.<<your thumb drawable here can be a selector>>);
f.set(o, drawable);
} catch (Exception e) {
e.printStackTrace();
}

关于android - 旧设备上的全息快速滚动外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14042269/

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