Ashish Kudale
Ashish Kudale

Reputation: 1260

Android : Unable to hide Toolbar or Action bar

I have multiple fragments in activity and on drawer item click I replace fragment. In one fragment I have a ListView. In this list, a user can select multiple items. I have a problem that when I select list item one more action bar is get added. I don't want that action bar.

Here is my screenshot

enter image description here

I wanted to merge them or hide toolbar while multiple selections. how can we solve this issue

Here is my code

BookingFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.fragment_booking, container, false);
    setHasOptionsMenu(true);
    lv_itemRateList = (ListView) v.findViewById(R.id.lv_itemRateList);
    lv_itemRateList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);

    lv_itemRateList.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {
            final int checkedCount = lv_itemRateList.getCheckedItemCount();
            actionMode.setTitle(checkedCount + " Selected");
            rateListAdapter.toggleSelection(i);
        }

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            actionMode.getMenuInflater().inflate(R.menu.context_main, menu);
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.menu_email:
                    SparseBooleanArray selected = rateListAdapter.getSelectedIds();
                    ArrayList<RateList> temp = new ArrayList<RateList>();
                    for (int i = 0; i < selected.size(); i++) {
                        temp.add(rateListAdapter.getItem(selected.keyAt(i)));
                    }
                    Log.e("array",""+temp);
                    //to do code.
                    actionMode.finish();
                    return true;
                default:
                    return false;
            }
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {
            rateListAdapter.removeSelection();
        }
    });

    return v;
}

Here is my activity theme

styles.xml

<style name="myTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionModeOverlay">true</item>
</style>

please help.

Upvotes: 2

Views: 1948

Answers (4)

Janmejoy
Janmejoy

Reputation: 2731

You can try Something like To Hide getActivity().getActionBar().hide(); To Show getActivity().getActionBar().show();

Upvotes: 1

SANJAY GUPTA
SANJAY GUPTA

Reputation: 1604

You need to make your theme like this.And this is working code. It will help you.

<resources>
    <style name="MultipleImageSelectTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/multiple_image_select_primary</item>
        <item name="colorPrimaryDark">@color/multiple_image_select_primaryDark</item>
        <item name="colorAccent">@color/multiple_image_select_accent</item>

        <item name="actionModeStyle">@style/CustomActionModeStyle</item>
        <item name="windowActionModeOverlay">true</item>
    </style>

    <style name="CustomActionModeStyle" parent="Base.Widget.AppCompat.ActionMode">
        <item name="background">@color/multiple_image_select_primary</item>
    </style>

    <style name="CustomToolbarTheme" parent="Base.ThemeOverlay.AppCompat.ActionBar">
        <item name="android:textColorPrimary">@color/multiple_image_select_toolbarPrimaryText</item>
    </style>
</resources>

Upvotes: 0

Mahesh Gawhane
Mahesh Gawhane

Reputation: 338

simply remove toolbar code from your xml and extend your base activity class with activity

Upvotes: -1

user6602265
user6602265

Reputation:

For hiding the toolbar you can just do :

getSupportActionBar().hide();

Upvotes: 1

Related Questions