Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display view on top of action bar

Is there a way to render a view on top of the action bar? I want to create a small tip box that will point the user to an item in the action bar. I know that a Toast with a set view will be rendered above the action bar. Does anyone know how to do this with a view?

I have attempted using FrameLayout with layout_gravity="top" and inflating a view and then adding it to the running activity's layout.

I appreciate you in advance.

Edit: Here is an image of what I was thinking: enter image description here

Edit: Perhaps some more detail is needed. I am looking for a way, or to find out if it is even possible to add a view to the view hierarchy of the activity so that it is rendered last.

Similar to CSS, I want a higher z-index order for this particular view ( the blue floating box in the image), such that it would be rendered on top of the Action Bar region in the activity. The view is in no way associated with Action Bar, it is simply drawn on top of it.

like image 670
lunaleaps Avatar asked Mar 07 '13 19:03

lunaleaps


People also ask

How do I customize my action bar?

This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I get the toolbar from action bar?

if you are using custom toolbar or ActionBar and you want to get reference of your toolbar/action bar from Fragments then you need to first get instance of your Main Activity from Fragment's onCreateView Method like below. ImageView vRightBtn = activity. toolbar. findViewById(R.

What is the difference between a toolbar and an action bar?

An Action bar is traditionally a part of an Activity opaque window decor controlled by the framework but a Toolbar may be placed at any level of nesting within a view hierarchy. The toolbar provides more feature than ActionBar . A Toolbar may contain a combination of elements from start to end.


1 Answers

I was trying to achieve something else but I needed a solution similar to this. I needed to draw an opaque layer covering the whole screen, even the action bar--sort of like a dialog. I did so this way:

ViewGroup vg = (ViewGroup)(getWindow().getDecorView().getRootView()); vg.addView(myNewView, params); 

this can be used to draw anything anywhere on the screen.

UPDATE: You really shouldn't be using ActionBar anymore, you wouldn't have this issue in the first place if you were using Toolbar like Android recommends. Toolbar would go inside your activity xml like a regular view and you can can do whatever you want to it. And its fully backwards compatible. https://developer.android.com/training/appbar/setting-up

like image 178
Siavash Avatar answered Sep 25 '22 13:09

Siavash