![]() |
VOOZH | about |
Emojis certainly make the app more interesting and fun to interact with. In this article, let's learn how to add Emojis in our own Android App by creating a simple application that looks like a messaging app.
Why do we need Emojis?
Step 1: Create a new Android Studio 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 the following dependency to build.gradle(:app)
In order to use emojis in the app, add its dependency to build.gradle(:app) file. Add any one of the three dependencies:
implementation 'com.vanniktech:emoji-google:0.6.0'
implementation 'com.vanniktech:emoji-ios:0.6.0'
implementation 'com.vanniktech:emoji-twitter:0.6.0'
Each dependency signifies the emoji set we are importing. That is, either from ios, or Google, or Twitter.
Step 3: Working with activity_main.xml file
In this example, make the app look like a chat app. For this, use two Buttons. One to add emojis and one to send the message. Add also an EditText where the user will type the message. This is how the activity_main.xml looks like:
Step 4: Create a layout file called text_view_emoji.xml
Create a layout to define how the emoji should look like. Its main purpose is to define the size of the emoji. It will also display the messages which we send. Create a new layout by clicking: app ->res -> layout(right-click) -> New -> Layout Resource File.
👁 newLayoutName this as text_view_emoji. This is how the text_view_emoji.xml looks like:
Step 5: Create a class called EmojiApplication
Depending on which emoji set the user wants to have, set up the corresponding providing here. By setting up the EmojiManager here, make sure that the user can use them anywhere in the app. To create a new class, click on: File -> New -> Java Class.
👁 newClassName this as EmojiApplication. This is how the EmojiApplication.java looks like:
Note: Do not forget to add this new class in the AndroidManifest.xml file. This is how the AndroidManifest.xml looks like after adding:
Step 6: Working with the MainActivity.java file
Here, write a function to inflate the EmojiTextView. The LayoutInfalter is used to convert a View or a ViewGroup written in XML to a View in Java which can use in the code. Also, set the onCreate() function here. After all these changes, this is how the MainActivity.java looks like: