Happy birthday app

Happy Birthday App in Android | Kotlin

In this tutorial, I will demonstrate to you how to develop a simple happy birthday app. The application design is very simple, provides exquisite cakes and birthday wishes, and is created in Kotlin language. If your friend’s birthday is coming and you want to surprise him or her with unique gifts and wishes, you may create an app for the birthday friend, and all of your friends can express themselves through the app.

Content :

  • Preview of Happy Birthday App
  • File: MainActivity.kt
  • File: activity_main.xml
  • File: BirthdayWish
  • File: activity_birthday_wish.xml

Learn Java Programming & get Certificate

Click to download

The goal of this tutorial is to familiarise you with Android Studio and guide you in creating your first Android application. The application is a straightforward Birthday greeting card (see the screenshot below.)

Preview: Happy Birthday Application

File: MainActivity.kt

–> In MainActivity.kt file initializes variable and implements intent for shuffle between activities.

package com.sagar.happybirthdayapp

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.createCard).setOnClickListener {
            val name = findViewById<EditText>(R.id.edittext_input).editableText.toString()
            Toast.makeText(this,"Name is $name",Toast.LENGTH_SHORT).show()

            val intent = Intent(this,BirthdayWish::class.java)
            intent.putExtra(BirthdayWish.INPUT_NAME,name)
            startActivity(intent)
         }

    }
}

File: activity_main.xml

–>activity_main.xml file contain edittext and button,textview.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/Preview_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="serif-monospace"
        android:gravity="center_horizontal"
        android:text="@string/insert_your_name_here"
        android:textAlignment="center"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.085" />

    <Button
        android:id="@+id/createCard"
        style="@style/TextAppearance.AppCompat.Widget.Button.Inverse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="287dp"
        android:backgroundTint="@color/black"
        android:text="Create Card"
        android:textColor="@color/teal_200"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <EditText
        android:id="@+id/edittext_input"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="169dp"
        android:background="@color/white"
        android:ems="10"
        android:fontFamily="serif-monospace"
        android:gravity="center_horizontal"
        android:hint="@string/sagar"
        android:inputType="textPersonName"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="25sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

File: BirthdayWish.kt

–> In BirthdayWish.kt file initializes variable and implements getstringextra method.

package com.sagar.happybirthdayapp

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView

class BirthdayWish : AppCompatActivity() {

    companion object{
        const val INPUT_NAME= "input_name "
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_birthday_wish)
        val name = intent.getStringExtra(INPUT_NAME)
        findViewById<TextView>(R.id.txt_birthday).text= "Many many returns of the day\n$name"

    }
}

File: activity_birthday_wish.xml

–> activity_birthday_wish.xml contain imageView and textview.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".BirthdayWish">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        app:srcCompat="@drawable/cake"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="31dp" />
    <TextView
        android:id="@+id/txt_birthday"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="43dp"
        android:text="Happy Birthday Dear"
        android:fontFamily="serif-monospace"
        android:textSize="30sp"
        android:textStyle="bold"
        android:textAlignment="center"
        android:textColor="@color/teal_700"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:gravity="center_horizontal" />



</androidx.constraintlayout.widget.ConstraintLayout>
  • We hope that this guide will assist you in quickly creating a simple Happy birthday Android application. If you have any problems, please post them in the comments section and we will gladly assist you.

This Post Has 4 Comments

Leave a Reply