How to use context action bar (CAB) with support for .v7.widget.Toolbar and Listview?

I am trying to use CAB with a ListView:

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 

This creates a CAB with an ActionBar by default, which overlays the toolbar in combination with this entry in my AppTheme:

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

It works, but it doesn’t look very good.

What I would like to achieve is similar to the current Gmail application if you click on an email address for a long time.

Any ideas how to achieve this?


I am using SupportActionBar:

 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); } 
+6
source share
1 answer

Since everything else works. I am sure that we are talking about stylization. You can always create it all.

  <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> 
+7
source

Source: https://habr.com/ru/post/979956/


All Articles