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?
- It makes the app look more user-friendly and fun.
- If the app features used for building communication, emojis certainly help to express a user’s feelings.
- It may be used to ask feedback of an app from the user.
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:
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.
Name 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.
Name 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:
Output: Run on Emulator
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- How to Publish Your Android App on Amazon App Store for Free?
- How to Integrate Facebook Audience Network (FAN) Banner Ads in Android?
- How to Integrate Facebook Audience Network (FAN) Rewarded Video Ads in Android?
- How to Integrate Google Admob Rewarded Video Ads in Android?
- How to Integrate Facebook Audience Network (FAN) Interstitial Ads in Android?
- How to Integrate Facebook Audience Network (FAN) Native Ads in Android?
- Android | Running your first Android app
- How to Add Audio Files to Android App in Android Studio?
- How to integrate Git Bash with Visual Studio Code?
- How to make a phone call from your Android App?
- Why Kotlin will replace Java for Android App Development
- App Development for Android in 2017: Challenges and Solutions
- Android | Creating a Calendar View app
- Adding Firebase to Android App
- How to change the color of Action Bar in an Android App?
- Android App Development Fundamentals for Beginners
- Android | App to Add Two Numbers
- Android | Creating multiple Screen app
- Activity Lifecycle in Android with Demo App
- How to build a simple Calculator app using Android Studio?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.