问题
I'm using Recylerview and want to show list like this https://i.stack.imgur.com/kMh1q.png
I've tried to enable fastScroll in xml as below however it only can change thumb and track of Recyclerview and can't show the text as I expected.
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:fastScrollEnabled="true"
app:fastScrollHorizontalThumbDrawable="@drawable/thumb_drawable"
app:fastScrollHorizontalTrackDrawable="@drawable/line_drawable"
app:fastScrollVerticalThumbDrawable="@drawable/thumb_drawable"
app:fastScrollVerticalTrackDrawable="@drawable/line_drawable"/>
I'm looking for attributes similar to fastScrollTextColor
and fastScrollPreviewBackgroundRight
in Recyclerview to shows text along scrollbar like in this example http://androidopentutorials.com/android-listview-fastscroll/ but it seem that RecyclerView doesn't support those
In that example uses ListView instead and these attributes can be declare in as styles of ListView
<style name="FastScrollStyle" parent="AppBaseTheme">
<item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
<item name="android:fastScrollOverlayPosition">atThumb</item>
<item name="android:fastScrollTextColor">@color/apptheme_color</item>
<item name="android:fastScrollTrackDrawable">@drawable/fastscroll_thumb_pressed_holo</item>
<item name="android:fastScrollPreviewBackgroundRight">@drawable/bg_default_focused_holo_light</item>
</style>
Anyone can help me do so with RecyclerView? Thanks!
回答1:
There's a library on github made for this purpose: https://github.com/viethoa/recyclerview-alphabet-fast-scroller-android
And I also found a project implementing it: https://github.com/codexpedia/android_fast_scroll_with_alphabet/tree/master/fast_scroll_with_alphabet2
来源:https://stackoverflow.com/questions/51296342/how-to-show-text-that-moves-along-scrollbar-using-recyclerview