From 8d5c0bc246edd4dbe923659c0e6e22cb461defda Mon Sep 17 00:00:00 2001 From: sicheng Yu Date: Wed, 4 Dec 2024 13:45:21 -0500 Subject: [PATCH] added way to display all author information on a custom dialog through toolbar menu in MainActivity --- .../com/example/camlingo/MainActivity.java | 22 ++++++++ .../main/res/layout/about_author_dialog.xml | 50 +++++++++++++++++++ app/src/main/res/menu/toolbar_menu.xml | 6 +++ 3 files changed, 78 insertions(+) create mode 100644 app/src/main/res/layout/about_author_dialog.xml diff --git a/app/src/main/java/com/example/camlingo/MainActivity.java b/app/src/main/java/com/example/camlingo/MainActivity.java index 75205a8..06ca079 100644 --- a/app/src/main/java/com/example/camlingo/MainActivity.java +++ b/app/src/main/java/com/example/camlingo/MainActivity.java @@ -1,9 +1,12 @@ package com.example.camlingo; +import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; + +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import androidx.cardview.widget.CardView; @@ -11,6 +14,7 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -123,6 +127,24 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + if (id == R.id.about) { + // Handle about action + AlertDialog.Builder customDialogBuilder = new AlertDialog.Builder(this); + View customView = getLayoutInflater().inflate(R.layout.about_author_dialog, null); + customDialogBuilder.setView(customView); + customDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Dismiss the dialog + dialog.dismiss(); + } + }); + AlertDialog aboutDialog = customDialogBuilder.create(); + aboutDialog.show(); + + return true; + } + return super.onOptionsItemSelected(item); } diff --git a/app/src/main/res/layout/about_author_dialog.xml b/app/src/main/res/layout/about_author_dialog.xml new file mode 100644 index 0000000..775bce6 --- /dev/null +++ b/app/src/main/res/layout/about_author_dialog.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/toolbar_menu.xml b/app/src/main/res/menu/toolbar_menu.xml index 3cd4409..57ae6f9 100644 --- a/app/src/main/res/menu/toolbar_menu.xml +++ b/app/src/main/res/menu/toolbar_menu.xml @@ -2,6 +2,12 @@ + +