Is there any possible way to display the three dots menu in action bar on divices with hardware menu button? Like Samsung Galaxy etc.
Looks like your answer is at the link below. There's an explanation of why you wouldn't want to do it, and another answer providing a hack to do it anyway (on android 4.x devices).
How to force use of overflow menu on devices with menu button
The guide says:
…
Menu items that are not promoted to an action item are available in the overflow menu, revealed by either the device Menu button (when available) or by an "overflow menu" button in the action bar (when the device does not include a Menu button).
In my app I have nested menu like:
//menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/three_dots_item"
android:icon="#drawable/ic_three_dots"
android:title="#string/title"
android:showAsAction="always">
<menu>
<!-- items to show -->
</menu>
</item>
</menu>
It's not real overflow, but it's a simple workaround.
This is worked for me
Use
<uses-sdk
android:minSdkVersion="8"
/>
instead of
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"/>
in manifest xml
Related
Not sure if this is the appropriate place for this question, but here goes. I'm following the android tutorial for creating apps and I'm finding some issues with the implementation of the menus in the action bar. (http://developer.android.com/training/basics/actionbar/setting-up.html). I am testing on my Samsung Galaxy S4.
I am making an App for Android 3.0 and above but when I follow those instructions, the menu doesn't appear in the action bar, but becomes visible only when I press the menu button. If I follow the Android 2.1 and above instructions, the menu buttons appear in the action bar, except the overflow menu which is activated by pressing the menu button.
What do I need to do for Android 3.0 and above to make the menu appear in the action bar? Or is this no longer the way it works and it is meant to appear using the menu button instead now?
In menu.xml use showAsAction="always"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_start"
android:showAsAction="always"
android:title="Start"/>
<item
android:id="#+id/action_signout"
android:showAsAction="always"
android:title="logout"/>
</menu>
I am developing an application of my own and was reading this: http://developer.android.com/guide/topics/ui/menus.html
It says:
Beginning with Android 3.0, the Menu button is deprecated (some
devices don't have one), so you should migrate toward using the action
bar to provide access to actions and other options.
My app is only targeting android 4.2+. Does that mean I should present the menu options as only action bar icons ? What if there is not enough room available ?
Items that do not fit in the action bar will automatically be relegated to the overflow menu. All you have to do is set the android:showAsAction="ifRoom" property in your xml for the menu item.
This basically tells the system that this menu item should be displayed as an action icon if there is room available. If not, it should be shown as an overflow menu item.
It means that there is no more hardware Menu Button. Your menu items will be showed in popup under "three-doted icon". In menu.xml you can configure everything:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_example"
android:title="#string/action_example"
android:showAsAction="ifRoom" /> <!-- attention -->
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
Read more here
If you need a lot of icons to be showed you can split ActionBar(second(bottom) menu bar will appear).
documantation of splitting
I hope mine explanation will be good enough:)
Hello and thank you for the time you take in reading this question.
I am trying to develop an android app which will use the ActionBar compat library. I have followed (as far as I see it) all the recommendations when using the compat library. My Manifest looks like this(only relevant code shown):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light" >
</application>
</manifest>
As you can see I am targeting sdk 8+. I have used the Theme.AppCompat theme as recommended.
My menu file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cds="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/action_map"
android:icon="#drawable/ic_action_map"
android:title="#string/action_map"
cds:showAsAction="ifRoom"/>
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
cds:showAsAction="ifRoom"/>
<item
android:id="#+id/action_mail"
android:icon="#drawable/ic_action_mail"
android:title="#string/action_mail"
cds:showAsAction="ifRoom"/>
</menu>
I am using my own namespace for the showAsAction attribute.
My activity extends the ActionBarActivity class.
The problem is this: On sdk 10 (android 2.3.3), both on device and emulator, the overflow menu (the three dots on the right side of the action bar) are not shown. Only the first 2 of the menu items are shown on the action bar. If i press the "Menu" button on the device then the third item is shown from the bottom left corner of the screen (not from the upper right corner as on the devices with more recent android versions). The same code works well on android sdk 17 on emulator (the overflow menu is shown with the proper actions).
I have searched the web for a solution but I could not find one with this specific problem. I would have abandoned the issue if I wouldn't have installed apps on the android 2.3.3 device that have the same action bar and which show the overflow menu icon and work properly like on any recent android device. One example of this app is the todoist app (https://en.todoist.com/android) or the handcent app(https://play.google.com/store/apps/details?id=com.handcent.nextsms&hl=en) which both behave well on this device.
Is there anything I am missing or is there an alternative solution to the recommended way of using the actionbar compat?
Thank you for your time.
#Andrei Google have disabled the menu overflow button in appcompat on pre honycomb.
If You really want to add it go to the android's github repository and download
platform_frameworks_support. It contains sorce for appcompat in platform_framework_support_master/v7/appcompat.
Create a libs folder inside appcompat and put latest android-support-v4.jar.
Now open file v7/appcompat/src/android/support/v7/internal/view/ActionBarPolicy.java.
You will see that showOverflowMenuButton is returned false for pre honycomb.Just return it true and add this edited appcompat as library to your project
and you will not need any custom overflow button
This worked with me.
Sorry for my English
EDIT: actual code from android/support/v7/internal/view/ActionBarPolicy.java
public boolean showsOverflowMenuButton() {
// Only show overflow on HC+ devices
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
Try to show as I did.
I add overflow menu (three dots) manually:
<item
android:id="#+id/menu_more"
android:icon="#drawable/abc_ic_menu_moreoverflow_normal_holo_light"
android:title="#string/action_settings"
myapp:showAsAction="always">
<menu>
<item
android:id="#+id/submenu_about"
android:showAsAction="always"
android:title="#string/menu_about"/>
</menu>
</item>
and override menu button click in activity to show this menu (solution from Opening submenu in action bar on Hardware menu button click):
private Menu mainMenu;
...
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP) {
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
mainMenu.performIdentifierAction(R.id.menu_more, 0);
return true;
}
}
return super.onKeyUp(keyCode, event);
}
Result on 2.2 looks like:
Hope it helps you.
I found the answer finally for this situation.
All you need to do is call the following in the OnCreate in your activity
ActionBarPolicy.get(this).showsOverflowMenuButton();
I'm having a problem when I try to set one item in my actionbar as always visible and 4 more icons as dropdown items with the following layout:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/search_movies"
android:icon="#drawable/action_search"
android:showAsAction="always"
android:title="Search"/>
<item
android:id="#+id/movies"
android:icon="#drawable/action_video"
android:showAsAction="collapseActionView"
android:title="Movies"/>
<item
android:id="#+id/theaters"
android:icon="#drawable/action_location_map"
android:showAsAction="collapseActionView"
android:title="Theaters"/>
<item
android:id="#+id/preferences"
android:icon="#drawable/action_settings"
android:showAsAction="collapseActionView"
android:title="Preferences"/>
<item
android:id="#+id/contact"
android:icon="#drawable/action_about"
android:showAsAction="collapseActionView"
android:title="Contact"/>
</menu>
The result is just the first item showing and the rest are not visible, not even as a dropdown. This is using ActionBarSherlock and a 2.3 Android device.
The question is, how can I get the icons to follow this layout:
EDIT:
The problem I had was because when you are using the actionbar with a device that has a "menu" hardware button the 3-dot dropdown does not shows off, the 4 other items are only displayed if you press the menu hardware button. Does anyone knows if this behaviour can be modified?
Hmmm, maybe I misunderstood, but if you wish to places those remaining four items into the overflow action menu (the 3-dot icon) then using android:showAsAction="never" instead of "collapseActionView" should do it.
...Tried a couple ways, but this did the trick:
Force overflow menu in ABS
I've met the same problem and my solution is quite simple. (I didn't use HoloEverywhere.)
The idea comes from the ABS sample project, whose drop-down menu can be displayed on pre-4.0 devices as well by using a submenu. So, my idea is using a submenu to disguise the 3-dot icon. Here's the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
SubMenu sub = menu.addSubMenu("More");
sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
sub.getItem().setIcon(R.drawable.ic_menu);
getSupportMenuInflater().inflate(R.menu.activity_main, sub);
return true;
}
Since the "More" menu doesn't have a MenuItem.SHOW_AS_ACTION_WITH_TEXT attribute, so the word "More"(or whatever you named) will actually not be displayed on the action bar. The only displayed icon R.drawable.ic_menu can be copied from ABS source code res/drawable-xxdpi folders named "abs__ic_menu_moreoverflow_normal_holo_dark.png", which is the so-called 3-dot icon. And the R.menu.activity_main is your menu xml.
It works!
In the Gmail app, the search bar moves all the way to the left when you click on the search icon. Does anyone know how to recreate this effect? The current way I have it, the icon expands when clicked, but doesn't move to the left like the Gmail app. Here is my menu xml file:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_search"
android:title="Search"
android:icon="#drawable/ic_menu_search"
android:showAsAction="ifRoom"
android:actionViewClass="android.widget.SearchView"
/>
</menu>
Take a look at this SO Question and see if that is what you're referring to:
Contextual Action Bar in Honeycomb
and
Contextual Action Bar in Honeycomb
The Gmail app seems to simply have a search icon in the menu and when you click on this it will add SearchView as the current navigation view with getActionBar.setCustomView().
There are a few gotchas when doing this, for example handling when it should be removed etc but if handled well it can lead to a nice user experience. But it may not be worth the hassle though, the regular expandable SearchView should be sufficient for most applications.