How to Use Balloon Library in Android?
Balloon Library is another popular feature that is commonly used in most Android Apps. You can get to see this feature in most of the shopping and messaging apps. With the help of this feature, you can get a hint about what to do next in any app. In this article, we are going to see how to implement balloon view in our Android App. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language.
Application of Balloon Library
- Balloon Library can be used to display hints of EditText for messaging app in an attractive way.
- It can be used to show the toast message in an Android app.
- Helps user about what to do next in Android app displaying hint text in it.
Attributes of Balloon Library
|.setWidthRatio()||Use to display the width of pop up according to ratio of horizontal screen size.|
|.showAlignBottom()||Use to display pop up at bottom.|
|.dismiss()||Use to dismiss pop up after it has been shown.|
|.setMargin()||Use to give margin from all sides.|
|.setIsVisibleArrow()||Use to show Arrow.|
|.setArrowPosition()||Use to set the position of arrow to the pop up.|
|.setArrowOrientation()||Use to set the orientation of the pop up.|
|.setText()||Use to display Text.|
|.setTextColor()||Use to display Text Color.|
|.setHeight()||Use to give height to pop up.|
|.setCornerRadius()||Use to make pop up rounded from all sides.|
|.setBalloonAnimation()||Use to give Animation to pop up.|
Step by Step Implementation
Step 1: Create a New Project
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.
Step 2: Add dependency of Balloon library in build.gradle file
Then Navigate to gradle scripts and then to build.gradle(Module) level. Add below line in build.gradle file in the dependencies section.
Now click on Sync now it will sync your all files in build.gradle().
Step 3: Create a new Balloon View in your activity_main.xml
Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.
Step 4: Working with the MainActivity.java file
Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file. Comments are added inside the code to understand the code in more detail.