From 849844e43e085466e7520fd7f034a5facb3b6d7f Mon Sep 17 00:00:00 2001 From: mysq <2706939842@qq.com> Date: Thu, 15 May 2025 18:01:10 +0800 Subject: [PATCH 1/2] lmy --- lmy.txt | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lmy.txt diff --git a/lmy.txt b/lmy.txt new file mode 100644 index 0000000..07b90b5 --- /dev/null +++ b/lmy.txt @@ -0,0 +1,55 @@ +public void supportInvalidateOptionsMenu() { + invalidateOptionsMenu(); // 最终调用 Activity 的原生方法 + } +if(secret_mode == 1) + menu.findItem(R.id.menu_secret).setVisible(false); + else + menu.findItem(R.id.menu_quit_secret).setVisible(false); + + + return true; + } + + + case R.id.menu_secret: { // 进入私密模式 + secret_mode = 1; // 先临时设为1(用于对话框标题提示) + AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this); + dialog.setTitle("重要提醒") + .setMessage("您确认进入私密模式吗?") + .setCancelable(false) + .setPositiveButton("确认", (d, which) -> { + startAsyncNotesListQuery(); + Toast.makeText(NotesListActivity.this, "您已进入私密模式", Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton("取消", (d, which) -> { + secret_mode = 0; // 恢复状态 + supportInvalidateOptionsMenu(); // 强制刷新菜单 + }) + .show(); + break; + } + case R.id.menu_quit_secret: { // 退出私密模式 + AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this); + dialog.setTitle("重要提醒") + .setMessage("您确认退出私密模式吗?") + .setCancelable(false) + .setPositiveButton("确认", (d, which) -> { + secret_mode = 0; + startAsyncNotesListQuery(); + supportInvalidateOptionsMenu(); // 刷新菜单 + Toast.makeText(NotesListActivity.this, "您已退出私密模式", Toast.LENGTH_SHORT).show(); + }) + .setNegativeButton("取消", null) // 无需操作 + .show(); + break; + } + +@Override +public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.note_list, menu); + MenuItem enterSecret = menu.findItem(R.id.menu_secret); + MenuItem quitSecret = menu.findItem(R.id.menu_quit_secret); + enterSecret.setVisible(secret_mode == 0); // 非私密模式时显示"进入" + quitSecret.setVisible(secret_mode == 1); // 私密模式时显示"退出" + return true; +} \ No newline at end of file From 6c6315cb0e7c9c9c1df6054bf09464e37ec9a557 Mon Sep 17 00:00:00 2001 From: mysq <2706939842@qq.com> Date: Thu, 15 May 2025 18:27:30 +0800 Subject: [PATCH 2/2] lmy --- lmy.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lmy.txt b/lmy.txt index 07b90b5..9f03bf8 100644 --- a/lmy.txt +++ b/lmy.txt @@ -1,3 +1,4 @@ +NoteListActivity类: public void supportInvalidateOptionsMenu() { invalidateOptionsMenu(); // 最终调用 Activity 的原生方法 } @@ -44,6 +45,7 @@ if(secret_mode == 1) break; } +ShareActionProvider: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.note_list, menu);