How do I remove the action bar/menu item from selecting a cell Android?

prankardprankard GBMember ✭✭

So on Android I'm having issue when changing page after selecting an item. I have my TableView inside one of the pages on a TabbedPage.
Once an cell is selected and the ContextActions are shown, the user can still change page.

When the page is changed, the top menu items do not disappear.

Does anyone have any idea how to remove this top bar?
I have tried removing the cells from the TableSection, or removing the menuitem listeners. But the top bar does not remove.

There must be a way to reference this somewhere via the context, custom renderer in some way. But I haven't figured it out yet.

Does anyone have any ideas?

Thanks

Best Answer

  • prankardprankard GB ✭✭
    Accepted Answer

    So I managed to hack together a solution.
    Nothing decent. But the MainActivity in android have some overloads when getting ActionModes. And I can call a method from the app to close the top bar.

    private static List<ActionMode> modes = new List<ActionMode>();
    private static List<Android.Support.V7.View.ActionMode> supportModes = new List<Android.Support.V7.View.ActionMode>();
    
    public override void OnActionModeStarted(ActionMode mode)
    {
        modes.Add(mode);
        base.OnActionModeStarted(mode);
    }
    
    public override void OnActionModeFinished(ActionMode mode)
    {
        modes.Remove(mode);
        base.OnActionModeFinished(mode);
    }
    
    public override void OnSupportActionModeStarted(Android.Support.V7.View.ActionMode mode)
    {
        supportModes.Add(mode);
        base.OnSupportActionModeStarted(mode);
    }
    
    public override void OnSupportActionModeFinished(Android.Support.V7.View.ActionMode mode)
    {
        supportModes.Remove(mode);
        base.OnSupportActionModeFinished(mode);
    }
    
    public static void CloseActionModes()
    {
        var _modes = modes.ToArray();
        foreach (ActionMode mode in modes)
        {
            mode.Finish();
        }
        var _supportModes = supportModes.ToArray();
        foreach (Android.Support.V7.View.ActionMode supportMode in _supportModes)
        {
            try
            {
                supportMode.Finish();
            }
            catch (Exception)
            { }
        }
    
        supportModes.Clear();
        modes.Clear();
    }
    

Answers

  • prankardprankard GBMember ✭✭

    Bump?

  • prankardprankard GBMember ✭✭
    Accepted Answer

    So I managed to hack together a solution.
    Nothing decent. But the MainActivity in android have some overloads when getting ActionModes. And I can call a method from the app to close the top bar.

    private static List<ActionMode> modes = new List<ActionMode>();
    private static List<Android.Support.V7.View.ActionMode> supportModes = new List<Android.Support.V7.View.ActionMode>();
    
    public override void OnActionModeStarted(ActionMode mode)
    {
        modes.Add(mode);
        base.OnActionModeStarted(mode);
    }
    
    public override void OnActionModeFinished(ActionMode mode)
    {
        modes.Remove(mode);
        base.OnActionModeFinished(mode);
    }
    
    public override void OnSupportActionModeStarted(Android.Support.V7.View.ActionMode mode)
    {
        supportModes.Add(mode);
        base.OnSupportActionModeStarted(mode);
    }
    
    public override void OnSupportActionModeFinished(Android.Support.V7.View.ActionMode mode)
    {
        supportModes.Remove(mode);
        base.OnSupportActionModeFinished(mode);
    }
    
    public static void CloseActionModes()
    {
        var _modes = modes.ToArray();
        foreach (ActionMode mode in modes)
        {
            mode.Finish();
        }
        var _supportModes = supportModes.ToArray();
        foreach (Android.Support.V7.View.ActionMode supportMode in _supportModes)
        {
            try
            {
                supportMode.Finish();
            }
            catch (Exception)
            { }
        }
    
        supportModes.Clear();
        modes.Clear();
    }
    
Sign In or Register to comment.