sTooltip

Additional

Language
Kotlin
Version
N/A
Created
May 1, 2019
Updated
Jan 29, 2020
Owner
jesus García (jesualex)
Contributor
jesus García (jesualex)
1
Activity
Badge
Generate
Download
Source code

Commercial

sTooltip

sTooltip is a simple Tooltip flexible and self-adjusting kotlin Library for Android.

Easy Use:

            Tooltip.on(exampleTextView)
                .text(R.string.example)
                .icon(android.R.drawable.ic_dialog_info)
                .iconSize(30, 30)
                .color(resources.getColor(R.color.colorPrimary))
                .overlay(resources.getColor(R.color.overlay))
                .border(Color.BLACK, 1f)
                .clickToHide(true)
                .corner(5)
                .position(Position.TOP)
                .show(3000)

First Steps

In your Project build.gradle you must have the following

buildscript {
    ...
    repositories {
        ...
        jcenter()
    }
    ...
    dependencies {
        ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    ...
}

In your App build.gradle you must have the following

...
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
...
dependencies {
    ...
    implementation 'cl.jesualex.android:stooltip:$last_version'
}

Options

Initialization of Builder

For your convenience, you can initialize the constructor only using the view to which you want the tooltip to refer, in that case the tooltip will be attached to the decorView(OVER ALL VIEWS)

Tooltip.on(View)

or if you wish you can add a root view and the tooltip will be ubicate inside of this view

Tooltip.on(View, View)

Builder options

Once the builder has been initialized, you can configure your tooltip, below you can briefly see the different methods you can use for that config

  • To set textbuilder.text(text)

  • To set text colorbuilder.textColor(colorInt)

  • To set text typefacebuilder.textTypeFace(typeface)

  • To set text sizebuilder.textSize(unit, textSize)builder.textSize(textSize)


  • To set text gravitybuilder.textGravity(TextViewGravity)

  • To enable a start icon(by default disabled)builder.iconStart(icon)

  • To set the start icon margin in pxbuilder.iconStartMargin(left, top, right, bottom)

  • To set the start icon size in pxbuilder.iconStartSize(h, w)

  • To enable a end icon(by default disabled)builder.iconEnd(icon)

  • To set the end icon margin in pxbuilder.iconEndMargin(left, top, right, bottom)

  • To set the end icon size in pxbuilder.iconEndSize(h, w)

  • To set a top drawablebuilder.drawableTop(drawable)

  • To set a bottom drawablebuilder.drawableBottom(drawable)

  • To set the tooltip bubble colorbuilder.color(color)

  • To set the tooltip content padding in pxbuilder.padding(top, right, bottom, left)

  • To set the position of the tooltip in relation to the view to which it points(by deafult Bottom)builder.position(position)

  • To set the corner radius in px of the tooltip bubblebuilder.corner(radius)

  • To enable autohide on tap(by default is enabled)builder.clickToHide(bool)

  • To set the distance in px between the tooltip and the view to which it pointsbuilder.distanceWithView(distance)

  • To set the the border color and width in pxbuilder.border(color, width)

  • To set the the border margin in pxbuilder.border(margin)

  • To enable and set a bubble shadow(by default bubble shadow radius is 0, it means shadow disabled)builder.shadow(radius, color)builder.shadow(radius)


  • To set shadow paddingbuilder.shadow(padding)

  • To set the arrow sizebuilder.arrowSize(h, w)

  • To set a tooltip minWidth in px if the space in parent isn't enough the tooltip will be relocated to the opposite positionbuilder.minWidth(w)

  • To set a tooltip minHeight in px if the space in parent isn't enough the tooltip will be relocated to the opposite positionbuilder.minHeight(w)

  • To set a tooltip show/hide animationbuilder.animation(animIn, animOut)builder.animation(anim)


  • To set a lifecycle listener to know when the tooltip has showed or hiddenbuilder.displayListener(listener)

  • To set a click listener to catch when the user click the tooltipbuilder.tooltipClickListener(listener)

  • To set a click listener to catch when the user click the view to which the tooltip pointsbuilder.refViewClickListener(listener)

  • To enable overlay function and set a listener to catch when the user click the overlay(by default the overlay click has disabled, it means that if the user clicks in the overlay, that click will be send to the view under the overlay)builder.overlay(color, listener)builder.overlay(color)


Show options

After configure your tooltip just left show it, if you want set a duration in millis and the tooltip will be autohide after that time(by default autohide is disabled)

builder.show()builder.show(duration)

This show method return a Tooltip instance, with which you can close, and show it again. If you call show before close, the tooltip will make a closeNow() and it will be shown again.

  • To close the tooltip with animationtooltip.close()

  • To close the tooltip without animationtooltip.closeNow()

tooltip.show()tooltip.show(duration, text)tooltip.show(text)
tooltip.show(duration)


  • To know if tooltip if currently showntooltip.isShown(): Boolean

Example

To get a small example, please download this repo and execute it

Thanks to:

License

Copyright 2019 Jesualex. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.