为了更改快速滚动fastScrollThumbDrawable的fastScrollTrackDrawable、 或文本颜色,SectionIndexer您必须使用上下文主题。其他答案建议通过覆盖应用程序的主题AndroidManifest来执行此操作。这确实有效,但如果你想要不同的滚动条外观,ListView你就不能这样做。此外,您更改文本颜色的方式SectionIndexer不应在您的应用主题中完成,因为它可能会产生其他不良影响。
为快速滚动设置样式的最佳方法ListView是创建一个ListView使用ContextThemeWrapper.
这是一个例子:
public class FastscrollThemedListView extends ListView {
public FastscrollThemedListView(Context context, AttributeSet attrs) {
super(new ContextThemeWrapper(context, R.style.FastScrollTheme), attrs);
}
}
这就是你所需要的。您的样式将如下所示:
<style name="FastScrollTheme">
<item name="android:textColorPrimary">?android:textColorPrimaryInverse</item>
<item name="android:fastScrollThumbDrawable">@drawable/fast_scrollbar_thumb</item>
<item name="android:fastScrollTrackDrawable">@drawable/fast_scrollbar_track</item>
</style>
textColorPrimary是你的钩子是你如何钩入SectionIndexer字体颜色,如果你使用它。
您的 ListView 将如下所示:
<com.yourapp.view.FastscrollThemedListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ListView"
android:fastScrollEnabled="true"
android:divider="@null"/>
如果你需要它,这就是你的 ThumbDrawable 的样子:
fast_scrollbar_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="10dp" android:bottom="10dp">
<shape android:shape="rectangle">
<size
android:height="45dp"
android:width="5dp" />
<solid android:color="#DA414A" />
</shape>
</item>
</layer-list>
AFAIK 没有为什么要在 HoneyComb 之前设置 FastScroll 栏的样式(API 11)