我有一个包含带有项目的ListVIEw的片段的Activity,用户可以在其上单击并调用上下文 *** 作模式.
我喜欢发生的是documentation所说的:
The contextual action bar is not necessarily associated with the
action bar. They operate independently, even though the contextual
action bar visually overtakes the action bar position.
但是,这是我目前正在经历的行为.截至目前,上下文 *** 作模式显示在Actionbar上方,如下图所示.
到目前为止我没有成功的尝试:
>将ActionMode逻辑从Fragment移动到主机Activity.
>设置< item name =“windowActionModeOverlay”> true< / item>在我的主题.
>调用getActivity().getMenuInflater()而不是mode.getMenuInflater().
这是我调用Contextual Action Menu的代码
public class NotesFragment extends Fragment implements VIEw.OnClickListener{ private ActionMode mActionMode; @OverrIDe public voID checkBoxChecked(Note which) { if (mActionMode == null) mActionMode = getActivity().startActionMode(mActionModeCallback); } private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() { // Called when the action mode is created; startActionMode() was called @OverrIDe public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate a menu resource provIDing context menu items MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.context, menu); return true; } // Called each time the action mode is shown. // Always called after onCreateActionMode, but // may be called multiple times if the mode is invalIDated. @OverrIDe public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; // Return false if nothing is done } // Called when the user selects a contextual menu item @OverrIDe public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemID()) { case R.ID.context_delete: //Do work unrelated to topic mode.finish(); // Action picked, so close the CAB return true; case R.ID.context_move: //Do work unrelated to topic mode.finish(); // Action picked, so close the CAB return true; default: return false; } } // Called when the user exits the action mode @OverrIDe public voID onDestroyActionMode(ActionMode mode) { mActionMode = null; } };}
编辑:
这是Fragment所在的Activity:
public class MainActivity extends ActionBaractivity implements DialogFragmentMoveNote.DialogFragmentMoveNoteListener, DialogFragmentRemoveNote.DialogFragmentRemoveNoteListener, DialogFragmentAddNewFolder.DialogFragmentAddNewFolderListener, DialogFragmentDeleteFolder.DialogFragmentDeleteFolderListener { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); } @OverrIDe public voID onAddNewFolderPositiveClick(Folder folder) { //Tell the fragment to do work } @OverrIDe public voID onRemoveNotesPositiveClick() { //Tell the fragment to do work } @OverrIDe public voID onMoveNotePositiveClick(String chosenFolder) { //Tell the fragment to do work } @OverrIDe public voID onDeleteFolderPositiveClick() { //Tell the fragment to do work } private voID displayNoteDetailsFromWidget(String noteID){ //Tell the fragment to do work }}
为什么上下文 *** 作菜单在视觉上不会超过Actionbar,因为文档状态应该是什么?
解决方法:
对此的解决方案是添加
<item name="androID:windowActionModeOverlay">true</item>
到我的主题,现在看起来像
<!-- Base application theme. --><style name="Apptheme" parent="theme.AppCompat.light.DarkActionbar"> <!-- Customize your theme here. --> <item name="androID:windowActionModeOverlay">true</item></style>
看完this answer后我找到了解决方案
总结以上是内存溢出为你收集整理的android – 上下文 *** 作菜单无法在视觉上超过片段中的 *** 作栏位置全部内容,希望文章能够帮你解决android – 上下文 *** 作菜单无法在视觉上超过片段中的 *** 作栏位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)