In this article, we will be building a Palindrome Checker android app in Android Studio using Kotlin and XML. The app will check whether the entered word is Palindrome or not, if the entered word is a Palindrome then a toast will be displayed having the message “Entered word is Palindrome” otherwise Toast’s message will be “Entered word is not a Palindrome”.
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 Kotlin as the programming language.
Step 2: Before going to the coding section first you have to do some pre-task
Add Colors: Add dark green and white color in your colors.xml file.
Change Theme: Change the theme to NoActionBar in the styles.xml file.
Make Gradient Background: create a new Drawable Resource file and name it “background.xml” inside the drawable directory and write the below code in it. Please refer to gradient background in android.
Step 3: Working with the activity_main.xml file
This file contains a TextView which displays the title of our app, an EditText view which takes the input from the user, and a Button view, on clicking which the app will check whether the entered word is Palindrome or not. Below is the code for the activity_main.xml file.
Step 4: Working with the MainActivity.kt file
Inside the class MainActivity, we will create a function “ispalindrome()” which will take a string value as a parameter and returns a Boolean value, it will return True if the string is Palindrome and if the string is not a Palindrome it will return False. Now, inside the onCreate function, we will call a setOnClickListener method on ButtonCheck, inside it, we pass the text value of editText to “ispalindrome()” function as an argument, if the returned value is True, we will display a Toast having message “Entered word is Palindrome” and if the returned value is False, we will display a Toast having the message “Entered word is not a Palindrome”. Below is the code for the MainActivity.kt file.