Skip to content

Documentation

Turing Technologies edited this page Mar 25, 2016 · 5 revisions

Note: All customisation methods (setAutoHide, setBarColour, etc) return the materialScrollBar, so they can be chained together if wanted. Alternatively, you can just operate on a variable.

####How to use - ScrollBar

The 'scrollBar' can be implemented programatically or through XML.

#####XML

The Google Now Launcher Option

<com.turingtechnologies.materialscrollbar.DragScrollBar
    android:id="@+id/dragScrollBar"
    android:layout_width="wrap_content"
    app:recyclerView="@id/recyclerView"
    app:lightOnTouch="[[boolean]]"
    android:layout_height="match_parent" />

or

The Google Messenger Option

<com.turingtechnologies.materialscrollbar.TouchScrollBar
    android:id="@+id/touchScrollBar"
    android:layout_width="wrap_content"
    app:recyclerView="@id/recyclerView"
    app:lightOnTouch="[[boolean]]"
    android:layout_height="match_parent" />

Additonal optional attributes:

  • handleColour - Colour
  • barColour - Colour
  • handleOffColour - Colour
  • textColour - Colour
  • barThickness - Integer

Please note that for both of these configurations, both recyclerView and lightOnTouch* must have a valid value. The recyclerView attribute should point to the id of the 'recyclerView' to which you want to link the scrollbar.

* lightOnTouch behaves as follows. A value of true will cause the handle to be grey until pressed, when it will become the normal accent colour (as set). A value of false will cause the handle to always have the accent colour, even when not being pressed.

#####Programmatically

The Google Now Launcher Option

DragScrollBar materialScrollBar = new DragScrollBar(this, recyclerView, {{lightOnTouch}});

or

The Google Messenger Option

TouchScrollBar materialScrollBar = new TouchScrollBar(this, recyclerView, {{lightOnTouch}});

where "recyclerView" is the object of the recyclerView to which you want to link the scrollBar. The difference between the two options is that the touch option hides after a cooldown period and touches anywhere on the track, whether on the button or not, scroll the view. The drag option on the other hand hides using the animation seen in the video and will only respond to touches on the handle. "lightOnTouch" can either be true or false. A value of true will cause the handle to be grey until pressed, when it will become the normal accent colour (as set). A value of false will cause the handle to always have the accent colour, even when not being pressed.

It is also strongly recommended that you provide the accent colour if your app supports devices below Lollipop. You can do this by invoking:

materialScrollBar.setHandleColour([[Accent Colour]]);

For devices running Lollipop and above, the accent colour will be read automatically. If you fail to provide an accent colour, devices running version of Android below Lollipop will default to a usable but bland grey colour.

####How to use - Indicator

To add an indicator, simply add the following line of code:

materialScrollBar.addIndicator({{Indicator}}, {{addSpace}});

If you implemented the bar programmatically, simply get the object using findViewById() and then the scrollbar's id.

The indicator should be either AlphatbetIndicator, DateAndTimeIndicator, or CustomIndicator. See below for specific instructions per indicator.

{{addSpace}} is a boolean which indicates whether there should be space in between the indicator and the bar. True adds space, as in the latest version of the Google Launcher, while false adds no space, as in the Android 5.1 system scrollbars.

To use an indicator, you MUST make your 'recyclerView''s adapter implement the relevant interface. If you do not, the library will throw a runtime error informing you of your mistake. See documentation for the relevant interface.

####Indicators #####AlphabetIndicator

Required Interface: INameableAdapter

To implement an AlphabetIndicator, which displays one character usually corresponding to the first letter of each item, add the following to the end of your 'materialScrollBar' instantiation, or add it as a seperate line.

...addIndicator(new AlphabetIndicator(this));

#####DateAndTimeIndicator

Required Interface: IDateableAdapter

To implement a DateAndTimeIndicator, which displays any combination of time, day of the month, month, and year, add the following to the end of your materialScrollBar instantiation, or add it as a seperate line.

...addIndicator(new DateAndTimeIndicator(this, {{includeYear}}, {{includeMonth}}, {{includeDay}}, {{includeTime}}));

All of the arguments are booleans (except for this first one obviously). The indicator will dynamically size, add punctuation, and localise for you. All you need to do is provide a Date object for each element in your adapter. You should almost always use miliseconds since the epoch unless you have a good reason not to. Otherwise, the library might crash.

#####CustomIndicator

Required Interface: ICustomAdapter

To implement a CustomIndicator, which displays any text you want, add the following to the end of your materialScrollBar instantiation, or add it as a seperate line.

...addIndicator(new CustomIndicator(this));

##Customisation Options

The following are various methods that you can invoke to customise the behaviour of the library.

####setHideDuration(int hideDuration)

Default: 2500

Use this to alter the hide duration of the bar. Only has effect if autoHide is true.

####setHandleColour(String|int colour)

Default: App designated accent colour (API 19+), Dark grey (API 18-)

Use this to alter the colour of the handle. If lightOnPress is true, this affects the lit colour.

####setHandleOffColour(String|int colour)

Default: Dark grey

Use this to alter the colour of the handle when unpressed. Only effective if lightOnPress is true.

####setBarColour(String|int colour)

Default: Light grey

Use this to alter the colour of the bar's background.

####setTextColour(String|int colour)

Default: White

Use this to alter the colour of text in the indicator. Useful if the background is unusually light and the text needs to be darkened.

####setAutoHide(Boolean autoHide)

Default: True

Use this to change whether the bar should deploy and hide as motion occours (true) or if it should always be present (false).

####setScrollBarHidden(Boolean hidden)

Default: false

Use this to change whether the bar should pretend like it doesn't exist. For example, if the recyclerView is empty or an animation requires the bar's removal.

####setDraggableFromAnywhere(Boolean draggableFromAnywhere)

Default: false

Only applies to DragScrollBar

Use this to change whether clicks on the bar but not on the handle should be recognised as valid.

Clone this wiki locally