Reputation: 989
I'm using a PopupWindow
to show some data when a user clicks a button on the action bar (using ABS). I'm also using an translate animation to show and hide the PopupWindow
so it drops down from the top.
The behavior I want is for the action bar to always remain on top of (Bring to front - like) everything else in the activity. But when I show the PopupWindow
the animation shows it coming down and overlapping the action bar as it travels. If I set a different height for the PopupWindow
it also overlaps the action bar.
Is there a way to use ActionBarSherlock to always show the action bar on top of everything else including popups and dialogs? Or is there some way to attach the PopupWindow
to the underlying fragment inside the root FrameLayout
?
Upvotes: 0
Views: 1168
Reputation: 3179
Take a look at your view in hierarchy viewer. The hierarchy here, including where ABS is, acts as the z-index for layers of views and view groups. You could grab a layer that is under the action bar and add a custom view to it:
// Grab android.R.id.content's parent to encompass the actionbar & user content
content = ((ViewGroup) findViewById(android.R.id.content).getParent());
// Make sure we inflate our menu resource before it is used
if (dialog == null)
dialog = (ViewGroup) <INFLATE SOME DIALOG/VIEWGROUP HERE>;
// We need this to add a view beneath the action bar
FrameLayout parent = (FrameLayout) content.getParent();
// There needs to be some layout params set for visibility
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP);
// A little tricky... using negative margins can do an initial translation that hides a view
layoutParams.setMargins(0, -(heightOfDialog), 0, 0);
dialog.setLayoutParams(layoutParams);
parent.addView(dialog, 0);
This should allow you to position a view beneath the dialog, and still be able to animate it how you would like using a class like TranslateAnimation:
TranslateAnimation animation = new TranslateAnimation(leftOfContent, 0, 0, 0);
animation.setDuration(TIME_TO_AUTO_SCROLL);
dialog.startAnimation(animation);
Upvotes: 2