How to customize GridView vertical scrollbar?

2019-09-11 03:34发布

问题:

I tried changing scrollbar of GridView:

android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"

scrollbar_vertical_thumb.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient
        android:angle="0"
        android:endColor="#005A87"
        android:startColor="#007AB8" />

    <corners android:radius="6dp" />

</shape>

scrollbar_vertical_track.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <gradient
        android:angle="0"
        android:endColor="#9BA3C5"
        android:startColor="#8388A4" />

    <corners android:radius="6dp" />

</shape>

But it's not working and gridview keeps showing original scrollbar.

回答1:

please try

android:scrollbarAlwaysDrawVerticalTrack=true
           android:scrollbars=vertical

if it didnt work then try android:scrollbarSize too