我在对话框的Imagview中打开了一个弹出菜单。单击菜单项时,我有一个语音朗读功能,它的倒数从10到1。我想在单击菜单项后关闭菜单。我尝试了popup.dismiss()和closeOptionsMenu()但没有运气。请帮帮我。
Imageview counter = (Imageview) findViewById(R.id.imgview);
counter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu countMenu = new PopupMenu(MainActivity.this,counter);
countMenu.getMenuInflater().inflate(R.menu.counter_menu,
countMenu.getMenu());
countMenu.setOnMenuItemClickListener(new
PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem menuItem) {
String selectedCount = menuItem.getTitle().toString();
countMenu.dismiss();
//Tried closeOptionsMenu(); too here but doesn't work
if(selectedCount.equals("Some String")
{
//TTS counter from 10 to 0
return true;
}
countMenu.show();
答案 0 :(得分:0)
返回 true 将不在您的 if 语句之内。您已将 return 语句置于 if 内语句,这就是计数结束后关闭的原因。
示例代码:
countMenu.dismiss();
return true;
if(selectedCount.equals("Some String")
{
//TTS counter from 10 to 0
}