跳转至

字母索引栏

Version 0.5.4

快速使用

Version 0.5.4

<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    android:id="@+id/alphabetsidebar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

查看默认样式

索引栏位置

Version 0.5.4

索引栏目前支持 左边右边 两种模式。可以通过 alphabetsidebar_location 和调用 setLocation 来进行设置。

mBinding.alphabetsidebar.setLocation(AlphabetSideBar.LEFT)
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_location="left" />

Location left Location right

背景颜色

Version 0.5.4

可以通过 alphabetsidebar_background 和调用 mBackgroundColor 来设置背景颜色。

mBinding.alphabetsidebar.mBackgroundColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_background="#26B2BEC3" />

Background

索引栏字体大小

Version 0.5.4

可以通过 alphabetsidebar_text_size 和调用 mBarTextSize 来设置索引栏字体大小。

mBinding.alphabetsidebar.mBarTextSize = 20f.SP
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_text_size="20sp" />

Text size

索引栏字体颜色

Version 0.5.4

可以通过 alphabetsidebar_text_color 和调用 mBarTextColor 来设置索引栏字体颜色。

mBinding.alphabetsidebar.mBarTextColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_text_color="#e17055" />

Text_color

当前索引字体颜色

Version 0.5.4

可以通过 alphabetsidebar_indicator_text_color 和调用 mBarIndicatorTextColor 来设置当前索引字体颜色。

左边是默认颜色,右边是修改后的颜色。

mBinding.alphabetsidebar.mBarIndicatorTextColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_indicator_text_color="#0984e3" />

Indicator text default color Indicator text color

气泡内文字大小

Version 0.5.4

可以通过 alphabetsidebar_bubble_text_size 和调用 mBubbleTextSize 来设置气泡内文字大小。

左边是默认大小,右边是修改后的大小。

mBinding.alphabetsidebar.mBubbleTextSize = 35f.SP
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_bubble_text_size="35sp" />

Bubble text default size Bubble text size

气泡内文字颜色

Version 0.5.4

可以通过 alphabetsidebar_bubble_text_color 和调用 mBubbleTextColor 来设置气泡内文字颜色。

左边是默认颜色,右边是修改后的颜色。

mBinding.alphabetsidebar.mBubbleTextColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
    ...
    app:alphabetsidebar_bubble_text_color="#4a69bd" />

Bubble text default color Bubble text default color

注册监听事件

Version 0.5.4

通过 setLetterListener 方法注册监听事件。

mBinding.alphabetsidebar.setLetterListener(object : AlphabetSideBar.LetterListener {
    override fun onIndicatorLetterUpdate(letter: String, index: Int, target: Int) {
        mBinding.recyclerView.smoothScrollToPosition(target)
    }
})

更新字母目标索引

Version 0.5.4

通过调用 setIndicatorLetterTargetIndex ,你可以更新字母的目标索引值,该索引值会被存储在 AlphabetSp 中。

mBinding.alphabetsidebar.setIndicatorLetterTargetIndex("A", target)

你可以通过 LetterListeneronIndicatorLetterTargetUpdate 方法监听目标索引的更新。

mBinding.alphabetsidebar.setLetterListener(object : AlphabetSideBar.LetterListener {
    ... // onIndicatorLetterUpdate 实现

    override fun onIndicatorLetterTargetUpdate(letter: String, target: Int) {
        mLogger.d(tag = "Gtest", "$letter 目标索引更新为 $target")
    }
})

示例代码

查看示例代码