如何自定义快速滚动预览字母

How to customize the fast scroll preview letter

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

您可以通过在 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>

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

PS:不要忘记在清单中将样式设置为 activity。

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

祝你好运。

感谢@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>