如何将上下文操作栏 (CAB) 与 support.v7.widget.Toolbar 和 Listview 一起使用



我正在尝试将 CAB 与列表视图一起使用:

listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new ListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            mode.setTitle(getString(R.string.list_selector_num_items_selected, listView.getCheckedItemCount()));
            Log.i("LIST",position + " selected");
        }
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return true;
        }
... and so on

这将创建带有默认操作栏的 CAB,该操作栏与我的应用程序主题中的此条目一起覆盖工具栏:

<item name="windowActionModeOverlay">true</item>

这正在工作,但看起来不是很好。

如果您长按电子邮件,我想实现的目标类似于当前的Gmail应用程序。

任何想法如何实现这一目标?


我正在使用支持操作栏:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
    setSupportActionBar(toolbar);
}

因为其他一切都在工作。我敢打赌这是关于造型的。您始终可以设置所有这些样式。

   <style name="AppTheme" parent="Theme.AppCompat">
            <!---- other atrributes -->
            <!--- changes the action mode style; height, text size, background etc -->
            <item name="actionModeStyle">@style/MyActionMode</item>
            <!--- changes left icon of that is used to close the action mode -->
            <item name="actionModeCloseDrawable">@drawable/ic_back</item>
    </style>


   <style name="MyActionMode" parent="Widget.AppCompat.Base.ActionMode">
 <!--- changes background of the container  -->
    <item name="background">?attr/colorPrimary</item>
 <!--- changes the action mode background when using actionbar is splitted -->
            <item name="backgroundSplit">?attr/colorPrimary</item>
 <!--- changes height of the actionmode container view -->
            <item name="height">@dimen/toolbar_size</item>
 <!--- changes text style of the title, create your own, this is the default  -->
            <item name="titleTextStyle">@style/TextAppearance.AppCompat.Widget.ActionMode.Title</item>
<!--- changes text style of the subtitle, create your own, this is the default  -->
            <item name="subtitleTextStyle">@style/TextAppearance.AppCompat.Widget.ActionMode.Subtitle
            </item>

最新更新