【问题标题】:Holo fast scroll look on old devices旧设备上的 Holo 快速滚动外观
【发布时间】:2012-12-26 14:55:51
【问题描述】:

关于我的应用

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

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

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

我想要做什么

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

我的问题

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

到目前为止我已经尝试过什么

  1. 正在寻找执行此操作的库。 HoloEverywhere 是 有希望但没有处理。

  2. 自己尝试过:

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

然后还添加了这个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:fastScrollThumbDrawabledoesn't exist pre-honeycomb


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

更新:

几个小时前,HoloEverywhere 似乎添加了快速滚动支持:

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

我会检查一下。 :)

【问题讨论】:

  • HoloEverywhere 解决了您的问题吗?
  • 我没有尝试将 HoloEverywhere 集成到我的应用程序中,但如果所有者接受了拉取请求,那么它肯定可以工作。我看了看他们是怎么做的,看起来很重。对我来说太多了,无法将它集成到我的应用中。

标签: android android-layout android-theme android-holo-everywhere fastscroll


【解决方案1】:

我正在使用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();
}

【讨论】:

    【解决方案2】:

    改变这个:

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

    对于这样的事情,你似乎忘记了一个属性:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    
    <style name="listviewfastscrollstyle" parent="android:Theme">
        <item name="android:fastScrollTrackDrawable">@drawable/fastscroll_thumb_holo</item>
        <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
    </style>
    
    </resources>
    

    现在应该可以了:)

    最好的问候

    野生动物园

    【讨论】:

    • 感谢您的回答。但这不起作用。请记住, android:fastScrollTrackDrawable 在蜂窝之前不存在。还有其他想法吗?
    • 哦,对不起,我忘记了,你的权利....嗯,我想新的东西..
    猜你喜欢
    • 2012-04-08
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多