You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GitProject/lmy.txt

57 lines
2.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

NoteListActivity类
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;
}
ShareActionProvider
@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;
}