【问题标题】:How to customize the fast scroll preview letter如何自定义快速滚动预览字母
【发布时间】:2015-05-25 14:42:46
【问题描述】:

我需要使用自定义背景资源自定义快速滚动字母预览(屏幕截图中的大 M),但我找不到任何有关它的文档。你能帮帮我吗?

【问题讨论】:

标签: android customization fastscroll


【解决方案1】:

感谢 @MAB 并查看 Lollipop 源代码,我设法获得了我需要的东西

我的c_fastscroller_preview.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners
    android:topLeftRadius="44dp"
    android:topRightRadius="44dp"
    android:bottomLeftRadius="44dp" />
<padding
    android:paddingLeft="22dp"
    android:paddingRight="22dp" />

<solid android:color="@color/c_red_e60000" /></shape>

c_fastscroller_thumb.xml 在哪里:

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

在我的应用程序styles.xml中:

        <!-- This belongs in a FastScroll style -->
    <item name="android:fastScrollThumbDrawable">@drawable/c_fastscroller_thumb</item>
    <item name="android:fastScrollPreviewBackgroundRight">@drawable/c_fastscroller_preview </item>
    <item name="android:fastScrollOverlayPosition">aboveThumb</item>
    <item name="android:fastScrollTextColor">@color/c_white</item>

【讨论】:

  • 它在 Lollipop 上完美运行,但在之前的 Android 版本中,fastScrollPreview 根本不显示。我该如何解决?
  • 奇怪!似乎 Holo 无法使用 aboveThumb 处理,但只能使用浮动和 atThumb(holo 源代码中的默认值)。但是使用其中一种材料的形状不太合适。因此,您可以尝试使用具有不同叠加位置和预览的 Holo 特定样式。
【解决方案2】:

您可以通过在res/values/styles.xml 下创建自定义样式来实现这一点

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb</item>
    <item name="android:fastScrollOverlayPosition">atThumb</item>
    <item name="android:fastScrollTextColor">@color/your_color</item>
    <item name="android:fastScrollTrackDrawable">@drawable/fastscroll_thumb_pressed</item>
</style>

fastScroll_thumb 是一个选择器

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/fastscroll_thumb_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/fastscroll_thumb_default"/>
</selector>

fastscroll_thumb_pressed/fastscroll_thumb_default 是您可以根据自己的喜好自定义的可绘制对象

PS:不要忘记在清单中为您的活动设置样式。

如果我错了,请纠正我,但我认为已经有很多问题在讨论同一个问题。

祝你好运。

【讨论】:

    猜你喜欢
    • 2015-09-28
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2012-02-29
    • 2018-08-25
    • 2011-07-26
    • 2017-05-10
    • 2011-07-06
    相关资源
    最近更新 更多