Tag Archives: The Android resource

Modifying the default style of scrollbar in Android

Well, I met the requirement again, and needed to modify the style of ScrollBar, so I looked up a lot of documents, I think the summary of this great cow is good, by the way, I took a look at his home page, wow, great ~!! Attach great god article links: http://likfe.com/archives/

knowledge points in the ListView/ScrollView/RecyclerView add attributes:
android: vertical scrollbars = “”
android: scrollbarTrackVertical =” @ drawable/xxx_vertical_track “
android: scrollbarThumbVertical =” @ drawable/xxx_vertical_thumb “
B: Horizontal scroll bar
android: horizontal scrollbars = “”
android: scrollbarTrackHorizontal =” @ drawable/xxx_horizontal_track “
android: scrollbarThumbHorizontal =” @ drawable/xxx_horizontal_thum “
other common attributes
defines the style and position of the scrollbar
android:scrollbarStyle= “outsideInset”
2. Define the size of the scroll bar, refers to the width, when the vertical level refers to the height of the
android: dp scrollbarSilbarSize = “4”

0

2

4

5

6

8

attributes effects
1 scrollbarThumbVertical[Horizontal] 3 short bars
7 scrollbarTrackVertical[Horizontal] 9 long bars, The background
Note that
where scrollbaTrackxxx, scrollbarThumbxxx can use:
◦ custom Shape

◦. ◦ can be registered for use.9. PNG
@color/ XXX to use color values
You cannot use the # XXXXXX color value directly
Android :scrollbarStyle can define the style and position of the scrollbar with four optional values including insideOverlay, insideInset, outsideOverlay and outsideInset.
Where inside and outside respectively mean whether the overlay is inside the padding of the view, overlay and inset mean whether the overlay is on the view or inserted behind the view, so the four values respectively represent:

0

3

4

6

attribute value effect of the

insideOverlay

default values, Inside the padding and overlaid on the view
means inside the padding and inserted behind the view
outsideInset 1 means outside the padding and inserted behind the view
5 outsideOverlay 7 inside the padding Outside and overlying the view

Demo
note:
scrollbarTrackVertical can be set to transparent or not directly set android: scrollbarTrackVertical = “@ color/transparent”
again: scrollbarThumbVertical, scrollbarTrackVertical can not directly set to color values, but you can use @ color
Layout:

android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
android:scrollbarSize="3dp"
android:scrollbars="vertical"

Demo 2
layout:

android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="@color/red_square"
android:scrollbarSize="3dp"
android:scrollbars="vertical”

default:

Demo2 effect:

Demo1 effect: