我试图在我们长时间点击button
项目时出现的Contextmenu中隐藏后面Listview
。我不知道如何访问actionMode菜单的项目,我尝试了actionMode.getMenu().getItem()
,但它没有向我显示后button
个ID。似乎项目是此菜单中的默认项目,因为我从不对它进行充气。
这里是代码:
_m_list_view.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
_m_list_view.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
_m_tweet_adaptateur.setChoiseMode(_m_list_view.getChoiceMode());
_m_list_view.setItemChecked(i, true);
return true;
}
});
_m_list_view.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {
updateActionModeTitle(actionMode);
if(_m_list_view.getCheckedItemCount()==0) {
_m_list_view.setChoiceMode(ListView.CHOICE_MODE_NONE);
}
}
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
mActionModeIsActive = true;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu_tweet, menu);
actionMode.setCustomView(LayoutInflater.from(MainActivity.this).inflate(R.layout.menu_select_tweet, null));
updateActionModeTitle(actionMode);
return(true);
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
switch (menuItem.getItemId()) {
//quand on appui sur ok dans le menu
case R.id.item_select_multi_tweet:
//code when ok
}
return true;
default:
return false;
}
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
//_m_list_view.setChoiceMode(ListView.CHOICE_MODE_NONE);
mActionModeIsActive = false;
_m_tweet_adaptateur.setChoiseMode(_m_list_view.getChoiceMode());
_m_list_view.setAdapter(_m_tweet_adaptateur);
}
});
我想要的只是删除/隐藏此项目:
谢谢!
答案 0 :(得分:2)
我找到了解决方案,我只需要将一个项actionModeCloseButtonStyle
添加到styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionModeCloseButtonStyle">@style/NoCloseButtonActionModeStyle</item>
</style>
<style name="NoCloseButtonActionModeStyle">
<item name="android:visibility">invisible</item>
</style>