Open In App
Related Articles

How to Build a Palindrome Checker App in Android Studio?

Like Article
Save Article
Report issue

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.


<?xml version="1.0" encoding="utf-8"?>
    <color name="colorPrimary">#6200EE</color>
    <color name="colorPrimaryDark">#3700B3</color>
    <color name="colorAccent">#03DAC5</color>
    <color name="white">#DFFAF7</color>
    <color name="DarkGreen">#216A33</color>


Change Theme: Change the theme to NoActionBar in the styles.xml file.


    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>


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.


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
            <gradient android:angle="90" 


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.


<?xml version="1.0" encoding="utf-8"?>
        android:text="GFG Palindrome Checker"
        app:layout_constraintTop_toTopOf="parent" />
        android:hint="Enter the Word"
        app:layout_constraintTop_toBottomOf="@+id/textView" />
        app:layout_constraintVertical_bias="0.095" />


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.


import android.os.Bundle
import android.widget.Toast
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        ButtonCheck.setOnClickListener {
            val text = editText.text.toString()
            if (ispalindrome(text)) {
                Toast.makeText(this, "Entered word is palindrome ", Toast.LENGTH_SHORT).show()
            } else {
                Toast.makeText(this, "Entered word is not a Palindrome", Toast.LENGTH_SHORT).show()
    private fun ispalindrome(text: String): Boolean {
        val reverseString = text.reversed().toString()
        return text.equals(reverseString, ignoreCase = true)



Last Updated : 21 Apr, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads