gpt4 book ai didi

android - 单击按钮时隐藏/显示选项菜单

转载 作者:行者123 更新时间:2023-11-29 19:16:32 28 4
gpt4 key购买 nike

我在 fragment 中使用了一些按钮。当我检查这些按钮时,应显示选项菜单。当我取消选中它时,它应该隐藏选项菜单。我应该怎么做

 @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
mLocation = getArguments().getString(Beco.EXTRA_LOCATION);
listMalls = temporaryModelCache.getDealData().getFacets().getArea();
listCategories = temporaryModelCache.getDealData().getFacets().getCategories();
listGender = temporaryModelCache.getDealData().getFacets().getAgeGroup();
try {
MainActivity activity = (MainActivity) getActivity();
if (activity != null) activity.hideBottomBar();
} catch (Exception ignored) {

}
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.forgot_password, menu);
mResetButton = menu.findItem(R.id.action_reset);
super.onCreateOptionsMenu(menu, inflater);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case R.id.action_reset:
Log.d(TAG, "onClick");
resetFilter();
return true;
}

return super.onOptionsItemSelected(item);
}

这是我需要隐藏/显示选项菜单的事件

private void checkSelected() {
if (!mapMall.isEmpty() || !mapGender.isEmpty() || !mapCategory.isEmpty()) {
footerTab.setVisibility(View.VISIBLE);

} else {
footerTab.setVisibility(View.GONE);
}
}

if (!mapMall.isEmpty() || !mapGender.isEmpty() || !mapCategory.isEmpty()) 我需要显示操作菜单并在 else 我需要隐藏选项菜单的部分!我怎样才能做到这一点?

最佳答案

调用 invalidateOptionsMenu() 隐藏和显示选项菜单

 Boolean Isreset= false;

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.forgot_password, menu);
mResetButton = menu.findItem(R.id.action_reset);
if(!Isreset)
{
mResetButton.setVisibility(true);
}else{
mResetButton.setVisibility(false);
}
super.onCreateOptionsMenu(menu, inflater);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch (itemId) {
case R.id.action_reset:
Log.d(TAG, "onClick");
resetFilter();
Isreset= true;
invalidateOptionsMenu();

return true;
}

return super.onOptionsItemSelected(item);
}

关于android - 单击按钮时隐藏/显示选项菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43346325/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com