First, you need to add some colors in the colors.xml file located in the res/values directory.


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="black">#FF000000</color>
    <color name="white">#FFFFFFFF</color>
    <color name="primaryColor">#512DA8</color> <!-- Deep Purple -->
    <color name="primaryDarkColor">#311B92</color>
    <color name="accentColor">#FF6F00</color>  <!-- Amber -->
    <color name="backgroundColor">#F3F4F6</color> <!-- light grey -->
    <color name="buttonColor">#00ACC1</color> <!-- Teal -->
    <color name="textColor">#212121</color>
</resources>


Now you need to set the style in your themes.xml file located in the res/values directory.


<style name="Theme.DoctorApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
        <item name="colorPrimary">@color/primaryColor</item>
        <item name="colorPrimaryVariant">@color/primaryDarkColor</item>
        <item name="colorOnPrimary">@android:color/white</item>
        <item name="colorAccent">@color/accentColor</item>
        <item name="android:colorBackground">@color/backgroundColor</item>
        <item name="android:textColor">@color/textColor</item>
        <item name="android:buttonStyle">@style/Widget.MaterialComponents.Button</item>
    </style>


I have added a button click animation. If you want to use this animation, make sure to create a directory named animator inside the res folder, and within it, create a resource file named button_press.xml. If you do not wish to use the animation, you can remove the related code from the Java file.

button_press.xml


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <objectAnimator
            android:propertyName="translationZ"
            android:duration="100"
            android:valueTo="2dp"
            android:valueType="floatType" />
    </item>
    <item>
        <objectAnimator
            android:propertyName="translationZ"
            android:duration="100"
            android:valueTo="6dp"
            android:valueType="floatType" />
    </item>
</selector>


activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:padding="24dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:text="Doctor Registration"
            android:textSize="24sp"
            android:textStyle="bold"
            android:textColor="@color/primaryColor"
            android:layout_gravity="center"
            android:layout_marginBottom="16dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="12dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/doc_id"
                android:hint="Doctor ID"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="12dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/first_name"
                android:hint="First Name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="12dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/last_name"
                android:hint="Last Name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="12dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/mobile"
                android:hint="Mobile Number"
                android:inputType="phone"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="12dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/address"
                android:hint="Address"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="12dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/city"
                android:hint="City"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:layout_marginBottom="20dp"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/specialization"
                android:hint="Specialization"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/submit_button"
            android:text="Submit"
            android:backgroundTint="@color/buttonColor"
            android:textColor="@android:color/white"
            android:stateListAnimator="@animator/button_press"
            android:elevation="6dp"
            android:layout_marginTop="12dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/search_button"
            android:text="Go to Search"
            android:layout_marginTop="10dp"
            android:backgroundTint="@color/accentColor"
            android:textColor="@android:color/white"
            android:elevation="6dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>

activity_search


<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="color/white"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="24dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:text="Search Doctor"
            android:textColor="@color/primaryColor"
            android:textSize="24sp"
            android:textStyle="bold" />

        <com.google.android.material.textfield.TextInputLayout
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/search_doc_id"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Enter Doctor ID"
                android:inputType="text" />
        </com.google.android.material.textfield.TextInputLayout>

        <Button
            android:id="@+id/search_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/buttonColor"
            android:elevation="6dp"
            android:stateListAnimator="@animator/button_press"
            android:text="Search"
            android:textColor="@android:color/white" />

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:backgroundTint="@android:color/white">

            <TextView
                android:id="@+id/result_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="20dp"
                android:text="Result will appear here"
                android:textColor="@color/textColor"
                android:textSize="16sp" />
        </androidx.cardview.widget.CardView>

    </LinearLayout>
</ScrollView>


DoctorDbHelper.java


package com.tecvipul.doctorinfosqlite;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DoctorDbHelper extends SQLiteOpenHelper {
    private static final String DB_NAME = "DoctorDB.db";
    private static final int DB_VERSION = 1;

    public DoctorDbHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE Doc_detail (" +
                "doc_id TEXT PRIMARY KEY, " +
                "firstname TEXT, " +
                "lastname TEXT, " +
                "mob TEXT, " +
                "address TEXT, " +
                "city TEXT, " +
                "specialization TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS Doc_detail");
        onCreate(db);
    }
}

MainActivity.java


package com.tecvipul.doctorinfosqlite;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    EditText docId, firstName, lastName, mobile, address, city, specialization;
    Button submitBtn, goToSearch;
    DoctorDbHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dbHelper = new DoctorDbHelper(this);

        docId = findViewById(R.id.doc_id);
        firstName = findViewById(R.id.first_name);
        lastName = findViewById(R.id.last_name);
        mobile = findViewById(R.id.mobile);
        address = findViewById(R.id.address);
        city = findViewById(R.id.city);
        specialization = findViewById(R.id.specialization);
        submitBtn = findViewById(R.id.submit_button);
        goToSearch = findViewById(R.id.search_button);

        submitBtn.setOnClickListener(v -> {
            SQLiteDatabase db = dbHelper.getWritableDatabase();
            ContentValues values = new ContentValues();
            values.put("doc_id", docId.getText().toString());
            values.put("firstname", firstName.getText().toString());
            values.put("lastname", lastName.getText().toString());
            values.put("mob", mobile.getText().toString());
            values.put("address", address.getText().toString());
            values.put("city", city.getText().toString());
            values.put("specialization", specialization.getText().toString());

            long newRowId = db.insert("Doc_detail", null, values);
            Toast.makeText(this, newRowId != -1 ? "Doctor added!" : "Error adding doctor", Toast.LENGTH_SHORT).show();
        });

        goToSearch.setOnClickListener(v -> startActivity(new Intent(this, SearchActivity.class)));
    }
}

SearchActivity.java


package com.tecvipul.doctorinfosqlite;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class SearchActivity extends AppCompatActivity {

    EditText docIdInput;
    Button searchBtn;
    TextView resultView;
    DoctorDbHelper dbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_search);

        docIdInput = findViewById(R.id.search_doc_id);
        searchBtn = findViewById(R.id.search_button);
        resultView = findViewById(R.id.result_text);
        dbHelper = new DoctorDbHelper(this);

        searchBtn.setOnClickListener(v -> {
            String docId = docIdInput.getText().toString();
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            Cursor cursor = db.rawQuery("SELECT * FROM Doc_detail WHERE doc_id = ?", new String[]{docId});

            if (cursor.moveToFirst()) {
                String info = "ID: " + cursor.getString(0) + "\n" +
                        "Name: " + cursor.getString(1) + " " + cursor.getString(2) + "\n" +
                        "Mobile: " + cursor.getString(3) + "\n" +
                        "Address: " + cursor.getString(4) + "\n" +
                        "City: " + cursor.getString(5) + "\n" +
                        "Specialization: " + cursor.getString(6);
                resultView.setText(info);
            } else {
                resultView.setText("Doctor not found.");
            }
            cursor.close();
        });
    }
}


Stay Connected With Us: If you have any query regarding this application, feel free to comment below. Also, don’t forget to follow this blog using the follow option on the right side.