Including in your project
Gradle
Add below codes to your root build.gradle
file (not your module build.gradle file).
And add a dependency code to your module's build.gradle
file.
SNAPSHOT
Snapshots of the current development version of Balloon are available, which track the latest versions.
Usage
Basic Example for Java
Here is a basic example of implementing balloon popup with icon and text using Balloon.Builder
class.
Create using kotlin dsl
This is how to create Balloon
instance using kotlin dsl.
Width and height
We can handle sizes of the popup width and height using the below ways.
If we would not set any specific sizes of the width/height of the balloon, the size of the popup will be decided by the content.
Padding
Balloon wraps a content. We can control the content size of the balloon using padding of the content.
Specific size
We can set the specific size of the balloon regardless size of the contents.
According to screen ratio
Also, we can set the width according to the ratio of the horizontal screen's size.
Show and dismiss
This is how to show balloon popup and dismiss.
We can set the balloon popup's position using x-Offset
and y-Offset
attributes.
And show based on top/bottom/right/left alignment if we use showAlign__
method.
Or we can show balloon popup using kotlin extension.
We can dismiss popup simply using Balloon.dismiss()
method.
We can dismiss automatically some milliseconds later when the popup is shown using
setAutoDismissDuration
method on Balloon.Builder
.
Show sequentially
We can show balloon popup sequentially using relayShow
method.
The relayShow
method makes that setOnDismissListener
of the first balloon is reset to show the
next balloon and returns an instance of the next balloon.
Margin
If the location of the balloon according to the anchor is located at the boundaries on the screen,
the balloon will be stick to the end of the screen. In that case, we can resolve by giving margins to the balloon.
Arrow Composition
We can customize the arrow on the balloon popup.
ArrowPositionRules
We can determine the position of the arrow depending on the aligning rules using the ArrowPositionRules
.
ArrowOrientationRules
We can determine the orientation of the arrow depending on the aligning rules using the ArrowOrientationRules
.
Below previews are implemented using setArrowOrientation
and setArrowPosition
methods.
setArrowPosition
measures the balloon popup size and sets the arrow's position using the ratio value.
Orientation: BOTTOM Position: 0.62 showAlignTop |
Orientation: TOP Position : 0.5 showAlignBottom |
Orientation: LEFT Position: 0.5 showAlignRight |
Orientation: RIGHT Position: 0.5 showAlignLeft |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Text Composition
We can customize the text on the balloon popup.
If your text has HTML in it, you can enable HTML rendering by adding this:
This will parse the text using Html.fromHtml(text)
.
TextForm
TextFrom is an attribute class that has some attributes about TextView for customizing popup text.
This is how to create TextForm
using kotlin dsl.
Icon Composition
We can customize the icon on the balloon popup.
IconForm
IconForm is an attribute class that has some attributes about ImageView for customizing popup icon.
This is how to create IconForm
using kotlin dsl.
OnBalloonClickListener, OnBalloonDismissListener, OnBalloonOutsideTouchListener
We can listen to the balloon popup is clicked, dismissed or touched outside using listeners.
We can simplify it using kotlin.
Customized layout
We can fully customize the balloon layout using below method.
This is an example of implementing custom balloon popup.

Firstly create an xml layout file like layout_custom_profile
on your taste.
And next we can get the inflated custom layout using getContentView
method.
Persistence
If you want to show-up the balloon popup only once or a specific number of times, here is how to implement it simply.
But you can implement it more variously using Only.
Avoid Memory leak
Dialog, PopupWindow and etc.. have memory leak issue if not dismissed before activity or fragment are destroyed.
But Lifecycles are now integrated with the Support Library since Architecture Components 1.0 Stable released.
So we can solve the memory leak issue so easily.
Just use setLifecycleOwner
method. Then dismiss
method will be called automatically before activity or fragment would be destroyed.
Lazy initialization
We can initialize the balloon property lazily using balloon
keyword and Balloon.Factory
abstract class.
The balloon
extension keyword can be used on Activity
, Fragment
, and View
.
Before
CustomActivity.kt
After
CustomActivity.kt
We should create a class which extends Balloon.Factory
.
An implementation class of the factory must have a default(non-argument) constructor.
ProfileBalloonFactory.kt
BalloonOverlay
We can show an overlay window over the whole screen except an anchor view.
We can change the shape of the highlighting using .setOverlayShape
.
OVAL | CIRCLE | RECT | ROUNDRECT |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
And we can set the specific position of the overlay shape using the below method.
BalloonAnimation
We can implement popup animations when showing and dismissing.
FADE | OVERSHOOT | ELASTIC | CIRCULAR |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Balloon builder methods
We can reference all kinds and descriptions of functions details here.