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:
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.
Try using ActionBar.setCustomView(). That's the only way to change the appearance of that area of the screen. You can't stick a View into the area "above" the ActionBar, because that area is basically controlled by the system. On the other hand, you can provide your own layout for it.
If you explain in more detail what you're trying to do, respondents might have some better design ideas.
Use the
android:actionLayout
in your menu.xml file.Then create your action_button_foo.xml layout:
To handle click do the following:
That's if :)
After struggling with it myself quite some time, here's the solution (tested it - working good):
The general steps are:
Let's see some code.
First, create a method to help create a wrapper view. the wrapper will be placed between the entire screen and the content of your app. being a ViewGroup you can later on fully control it's content.
Now, interfere with the regular Activity creation, and instead of using setContentView, use the method we've created.
That's about it.
Notes
0
and1
indexes)EDIT: Refer to @CristopherOyarzúnAltamirano Answer for further support on newer Android versions
Good luck!
There is a much simpler way to achieve this. ActionBar holds its layout in the class ActionBarContainer which simply inherits from FrameLayout. So in order to display something over the ActionBar you need to grab a reference to the ActionBarContainer and add your own custom View into it. Here is the code
(Reference: http://www.vogella.com/articles/AndroidActionBar/article.html)
Custom Views in the
ActionBar
You can also add a custom View to the
ActionBar
. For this you use thesetCustomView
method for theActionView
class. You also have to enable the display of custom views via thesetDisplayOptions()
method by passing in theActionBar.DISPLAY_SHOW_CUSTOM
flag.For example you can define a layout file which contains a
EditText
element.This layout can be assigned to the
ActionBar
via the following code. The example code allow attaches a listener to the custom view.https://github.com/michaelye/EasyDialogDemo
see the demo above,it may help you
you could set the location[] yourself.