After i added an action bar to my android app, the menu moved to the action bar.. What's i'm trying to do is to make the action bar at the top, and keep the menu in bottom as it was before. Is it possible to make menu independent from action bar?
You can use a Split Action Bar to position action items and the overflow menu (the three dot menu) along the bottom of your device on phones in portrait (phones in landscape and tablets will still have it in the action bar).
If you really have a good reason to put the overflow menu in a different spot (potentially confusing users who are expecting to have it in the action bar/split action bar positions), you can add a PopupMenu to any location in your layout to add a menu that acts similar to how the Action Bar overflow menu works.
Related
Been trying everything to show the menu item search (searchWidget) in the actionbar. I have a navigationdrawer, which doesn't hide the actionbar items at any time. But still the search item is always at the overflow, even when having a large screen device.
I have tried using always in the showAsAction in the menu item, and even putting the menu item as visible in the onPrepareOptionsMenu method, and calling it when the drawer opens and closes to see if something changed, and still nothing.
I won't post code now, just wondering if someone had the same problem. If necessary I will post code of course.
If you are using regular action bar menu items (API 13+) then you simply need to say -
android:showAsAction="always"
for that menu item in the menu resource.
However, if you are using the compat library - appcompat-v7 for action bar and menu items (API 7+) then you need your app's name as the namespace as -
yourapp:showAsAction="always"
and add the following to menu tag at the top with the android namespace as -
xmlns:yourapp="http://schemas.android.com/apk/res-auto"
I have an app with a normal menu i.e. the common old menu that shows up at the bottom of the screen when the menu button is pressed. But it is a problem in some phones where there is no hard menu button.
I want to switch to slider menu with a menu icon on top. Is there an easy way to do this (I mean a way where code change would be minimum) retaining the existing functionality? Or will i have to go about coding the slider menu from scratch?
Any example code of a similar situation would really help.
I have an app with a normal menu i.e. the common old menu that shows up at the bottom of the screen when the menu button is pressed
Normally, that "menu" will appear as the overflow on devices with an action bar that either:
do not have a MENU button, or
run Android 4.4+
But it is a problem in some phones where there is no hard menu button.
Make sure that your app has an action bar.
I want to switch to slider menu with a menu icon on top
The options menu/action-bar-with-overflow is unrelated to the "slider menu". They serve different roles. Please read the design guidelines for a navigation drawer (a.k.a., "slider menu").
Is there an easy way to do this (I mean a way where code change would be minimum) retaining the existing functionality?
No, because they are not related.
I set the background of my action bar, but in split mode the background does not work.
I see that I must set this :
<item name="android:backgroundSplit">#drawable/some_drowable</item>
but it does not work in Api level 11
Is there any other way to do this ?
I have another question about action bar style, I want to change action bar icon color when it is pressed (not background area, but replace the icon). How can I do this ?
The first, I don't know how to do that. But the second, I can help you with. It's not that difficult at all.
Basically, the action bar is just a bar with any menu options that you otherwise would have set under the menu button.
As such, it is created on the start of your application with a call to
#Override
public boolean onCreateOptionsMenu(Menu menu) {
...
}
And any selected options will cause
#Override
public boolean onOptionItemSelected(MenuItem item) {
...
}
to be called, with the menu item that the user selected.
However, there is a third method that relates to the options menu, which is the one you want to use to update the action. It is called onPrepareOptionsMenu(Menu menu) (link). In this method, it is allowed to alter the menu that is created with onCreateOptionsMenu(...).
So, with this knowledge, you can keep a (global) state for a specific item in onOptionsItemSelected(...) by checking which action was tapped in the action bar by calling item.getItemId().
Now, you will have the knowledge of which action was tapped on the action bar, and the state you want it to be in.
But wait, the action bar was already created when the application launched. So how do you cause the it to be re-created? Very simple actually. You merely need a call to invalidateOptionsMenu() (link) to invalidate it. this causes Android to redraw the action bar, and causing the whole line of onCreateOptionsMenu(...) -> onPrepareOptionsMenu(...) to be called again.
So now you have everything you need:
Determine what action has been tapped by the user (onOptionsItemSelected(...)
What state you want to keep
How to redraw the action bar
When the action bar is being redrawn, you can change the icons for the items on the action bar so it will update to the state you want it to be.
I'm creating an action bar on ICS. Due to spacing only the icons are displayed.
But I'd also like to supply the action bar as context-like menu with text if the menu button of the phone is pressed.
How can I achieve this?
Atm I have 3 icons. 2 of them are displayed at the top in action bar.
If I press the menu phone button, the 3rd is displayed as contextmenu! But I'd like to have all 3 of them.
class MyActivity extends SherlockFragmentActivity {
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
/* IMPLEMENTATION HERE */
}
}
From the documentation on Menus:
If a menu item does not appear as an action item, then the system places it in the overflow menu.
Thus, showing the same action item in both the action bar and the overflow menu is not possible. What you could do is this:
Check (at runtime) which menu items fit in the Action Bar and which do not.
For each menu item that is displayed in the Action Bar, create a new, identical menu item dynamically, making sure to call newMenuItem.setShowAsAction(SHOW_AS_ACTION_NEVER) to ensure that it is displayed in the overflow menu (w/ text).
This, in my opinion, goes against Android's menu design standards and I wouldn't suggest doing it. It might appear like a better design choice in your eyes, but users expect apps to be consistent across the entire Android platform. Manipulating your menus in weird ways can cause confusion, and can negatively impact user experience as a result.
I have a problem. You see, I want to add my own items to the window menu bar of my application, not add items to a JMenuBar. Like for example, look at the menu bar of the browser you are using. That type of menu bar. I know Java is run in a VM so you can't access too many things outside of the JVM, but is there any possible way that can be done? Whenever I search "Java menu bar" it comes up with just JMenuBar stuff and nothing about creating a window menu bar. Thanks!
You can make the JMenuBar look however you want. You just need to configure the menu bar and its menus appropriately.