Change scrollbar color in Android

后端 未结 2 1611
孤独总比滥情好
孤独总比滥情好 2020-12-04 15:19

Is it possible to change the color or appearance of the scrollbar in a ScrollView or ListView?

相关标签:
2条回答
  • 2020-12-04 16:14

    You can set Listview property as

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

    Here custom_scroll_style is a xml file under the drawable folder. Lets create the custom_scroll_style.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <gradient
        android:angle="45"
        android:endColor="#FF3401"
        android:centerColor="#ff5c33"
        android:startColor="#FF3401" />
    
    <corners android:radius="8dp" />
    <size android:width="4dp"/>
    <padding
        android:left="0.5dp"
        android:right="0.5dp" />
    
    </shape>
    

    Here I got a Orange color scrollbar. You can use images also if the image size is less than 2px instead of xml.

    0 讨论(0)
  • 2020-12-04 16:15

    Check out the ApiDemos sample project in the SDK. The layout res/layout/scrollbar2.xml shows a way to style scroll bars.

    There are separate attributes for the scrollbar track and the scrollbar thumb. Size can also be adjusted.

    0 讨论(0)
提交回复
热议问题