字母索引栏¶
快速使用¶
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
android:id="@+id/alphabetsidebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
索引栏位置¶
索引栏目前支持 左边 和 右边 两种模式。可以通过 alphabetsidebar_location
和调用 setLocation
来进行设置。
mBinding.alphabetsidebar.setLocation(AlphabetSideBar.LEFT)
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_location="left" />
背景颜色¶
可以通过 alphabetsidebar_background
和调用 mBackgroundColor
来设置背景颜色。
mBinding.alphabetsidebar.mBackgroundColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_background="#26B2BEC3" />
索引栏字体大小¶
可以通过 alphabetsidebar_text_size
和调用 mBarTextSize
来设置索引栏字体大小。
mBinding.alphabetsidebar.mBarTextSize = 20f.SP
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_text_size="20sp" />
索引栏字体颜色¶
可以通过 alphabetsidebar_text_color
和调用 mBarTextColor
来设置索引栏字体颜色。
mBinding.alphabetsidebar.mBarTextColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_text_color="#e17055" />
当前索引字体颜色¶
可以通过 alphabetsidebar_indicator_text_color
和调用 mBarIndicatorTextColor
来设置当前索引字体颜色。
左边是默认颜色,右边是修改后的颜色。
mBinding.alphabetsidebar.mBarIndicatorTextColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_indicator_text_color="#0984e3" />
气泡内文字大小¶
可以通过 alphabetsidebar_bubble_text_size
和调用 mBubbleTextSize
来设置气泡内文字大小。
左边是默认大小,右边是修改后的大小。
mBinding.alphabetsidebar.mBubbleTextSize = 35f.SP
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_bubble_text_size="35sp" />
气泡内文字颜色¶
可以通过 alphabetsidebar_bubble_text_color
和调用 mBubbleTextColor
来设置气泡内文字颜色。
左边是默认颜色,右边是修改后的颜色。
mBinding.alphabetsidebar.mBubbleTextColor = ...
<com.ave.vastgui.tools.view.alphabetsidebar.AlphabetSideBar
...
app:alphabetsidebar_bubble_text_color="#4a69bd" />
注册监听事件¶
通过 setLetterListener
方法注册监听事件。
mBinding.alphabetsidebar.setLetterListener(object : AlphabetSideBar.LetterListener {
override fun onIndicatorLetterUpdate(letter: String, index: Int, target: Int) {
mBinding.recyclerView.smoothScrollToPosition(target)
}
})
更新字母目标索引¶
通过调用 setIndicatorLetterTargetIndex
,你可以更新字母的目标索引值,该索引值会被存储在 AlphabetSp 中。
mBinding.alphabetsidebar.setIndicatorLetterTargetIndex("A", target)
你可以通过 LetterListener
的 onIndicatorLetterTargetUpdate
方法监听目标索引的更新。
mBinding.alphabetsidebar.setLetterListener(object : AlphabetSideBar.LetterListener {
... // onIndicatorLetterUpdate 实现
override fun onIndicatorLetterTargetUpdate(letter: String, target: Int) {
mLogger.d(tag = "Gtest", "$letter 目标索引更新为 $target")
}
})