更改 ListView 的 ScrollBar/FastScroll 颜色?

Change ListView's ScrollBar/FastScroll color?

我的应用程序全部采用橙色主题,但 ScrollBar/FastScroll 显示为绿色。我尝试了很多搜索,但找不到任何方法来改变这一点。它只是保持原样。

我找到了 "android:fastScrollTextColor" 属性 但这改变了气泡内 B 的颜色。而且我找不到任何 属性 来更改此气泡或旁边的 ScrollBar 的颜色。

以防万一,我正在使用从 here 获得的自定义 PinnedHeaderListView 来模仿棒棒糖联系人应用程序中的粘性 headers。

在 xml 文件的 listView 属性中设置此项。

android:scrollbarSize="10dp"
android:scrollbarThumbVertical="@drawable/custom_scroll_style"

这里custom_scroll_style是drawable文件夹下的一个xml文件。让我们创建 custom_scroll_style.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:angle="45"
    android:endColor="@color/endColor" //define what you want
    android:centerColor="@color/centercolor"
    android:startColor="@color/startColor" />

<corners android:radius="8dp" />
<size android:width="4dp"/>
<padding
    android:left="0.5dp"
    android:right="0.5dp" />

</shape>

希望对您有所帮助!

滚动条缩略图颜色已设置为应用主题中的 android:colorAccent 属性。您确定设置正确,对吗?

请注意,如果您使用的是 AppCompat,则必须从属性中排除 android: 前缀。

您可以找到有关可用颜色属性的更多信息here

android:scrollbarThumbVertical 可以正常工作。但是,如果在 listView 中启用了快速滚动,您应该在 AppTheme 或任何主题中定义 android:fastScrollThumbDrawable,并将其用于包含列表视图的 activity(在 AndroidManifest 中)启用快速滚动。

styles.xml的一部分

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:fastScrollThumbDrawable">@drawable/fast_scrollbar_vertical</item>
</style>

清单的一部分

    <activity
        android:name=".ListActivity"
        android:label="@string/title_activity_list"
        android:theme="@style/AppTheme" />

并且可绘制的滚动条应该是渐变的

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<gradient
    android:angle="45"
    android:endColor="@color/scroll_color"
    android:centerColor="@color/scroll_color"
    android:startColor="@color/scroll_color" />

<corners android:radius="8dp" />
<size android:width="8dp" android:height="100dp"/>
<padding
    android:left="0.5dp"
    android:right="0.5dp" />

</shape>