-1

My question is pretty simple.
How can I get a Contextual Action Bar (CAB) visibility?

For instance, I have a ActionMode and a callback.

mActionMode = activity.startActionMode(mCallback);

Now I need to know if the CAB is visible or not. Any ideas?

rafaelc
  • 57,686
  • 15
  • 58
  • 82

2 Answers2

1

There is no way of querying that. But the answer suggested by @RafaelC is unnecessary(sorry mate no hard feelings)... your code is already designed so u can know when is visible. See when u start the action mode, a reference to the ActionMode object is saved in your member variable:

mActionMode = activity.startActionMode(mCallback);

Then in your onDestroyActionMode, if you dont have it yet add this line:

mActioinMode=null;

That's it!

Now:

if(mActionMode!=null) //your ActionMode bar is visible

if(mActionMode==null) //your ActinMode bar is not visible.

Hope this helps new coders... Regards :)

Osagui Aghedo
  • 330
  • 4
  • 12
  • Hi Osagui, thanks for chipping in. This question is from 3 years ago, and I haven't done any more Android since then. Don't remember a thing haha :} Will keep both answers as alternative for future ppl coming from google ! – rafaelc May 03 '19 at 13:18
-1

I guess there is no built-in solution for this problem.

I have solved it by setting a boolean flag in my callback class

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu)
{
    this.visible = true;
    /**/
    return true;
}

and

@Override
public void onDestroyActionMode(ActionMode mode)
{       
    this.visible = false;
    /**/
}

Then, it is possible to use callback.isVisible();

rafaelc
  • 57,686
  • 15
  • 58
  • 82