3

I'm using Android Studio (actually on Mac), only using real devices

This is 4.1+ only. All projects created from fresh.

CHECK - I did load support and appcompat, as best as I can understand Gradle. [A]

enter image description here

CHECK - onCreateOptionsMenu, etc, looks good...

enter image description here

CHECK - xml is good to go. (I do totally understand the showAsAction options, and tried them all.) [B] Regarding using text or an icon, I tried all permutations.

enter image description here

So what happens?

When I run it on a device (10+ tested). It simply shows as many action bar items as can fit (say, 5 or so). Rotation etc. works perfectly.

But it just will not show the overflow icon!! WTF?? It simply does not show, anywhere, the missing three or four items.

I have tried all this with both "Blank Activity" and "Fullscreen Activity". No matter WHAT I do, it won't show the @#$@ overflow.

It's almost like the icon is just not available in the build or something??

Can any Android friends psychic this problem? It's a really "WTF" moment. Thanks in advance.

My workaround ... https://stackoverflow.com/a/22855136/294884 That works great, but you Android guys would laugh at me doing that.

[A]: (Note that I have two build.gradle files; I did it on the inner one inside app/ . Wouldn't work on the outer one.)

[B]: (Note, a common question seems to be when people don't get the difference between 'always' and 'ifRoom'. TBC that is not my problem at all: my problem is the @$@# overflow simply will not appear!!)


BTW for anyone new to Android ...

https://stackoverflow.com/a/16046189/294884

that extended discussion may be very useful.

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 1
    are you using only Samsung devices (or other devices that do have a "Menu" hardware button) ? – Budius May 18 '14 at 11:00
  • Hi Budius .. just to be clear, it also DOES NOT make the physical MENU button work. I will triple-check on devices that have NO physical MENU button,a nd get back to you. – Fattie May 18 '14 at 11:01
  • 1
    That will be my best guest. Devices with hardware button don't show the 3-dots menu. By the way: if the project is 4.1+ you don't need neither support-v4 nor appcompat-v7 – Budius May 18 '14 at 11:08

4 Answers4

8

Press "File" in the top left corner of Android Studio, select "Project Structure...". A Dialog will be opened with a list of modules in the left side.

Select the module of your project, go to the tab "Dependencies", press the green "+" on the right, select "Library Dependencies" in the next Dialog you will be able to add the libraries you want.

If "Support v4" and "AppCompat" are not available you should first install "Android Support Library" and "Google Repository" via the Android SDK Manager.

enter image description here

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
Patrick Leitermann
  • 2,144
  • 2
  • 13
  • 13
  • Absolutely **AMAZING TIP**, thank you so much. However, tragically my project seems to **already have** the two libraries in there :/ – Fattie May 18 '14 at 11:09
  • 1
    Finally your Activity must extend android.support.v7.ActionBarActivity not android.app.Activity and instead of getActionBar() getSupportActionBar() must be used. – Patrick Leitermann May 18 '14 at 11:13
  • I believe, if you do NOT use a fragment, you can just extend "Activity" .. .is that right? That's what it seems to suggest here: http://developer.android.com/guide/topics/ui/actionbar.html BTW is your understanding, as Budius says, that if the device **does have** a physical KEYCODE_MENU button, then android **will only use** that button and **not** show an overflow icon up top? – Fattie May 18 '14 at 11:19
  • You two dudes friction' saved the day :) If you ever need to know like the size of an icon on iOS, be sure to ask me :) – Fattie May 18 '14 at 11:21
  • 1
    :D Sorry, it could be that I missunterstood the queston, because I was so concentrated at the support library and I`ve always developed my apps with backwards compatibility :D By the way in the solution with the support library the following code was missing in onCreate: ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); – Patrick Leitermann May 18 '14 at 11:30
  • Exactly man! :) I'm a typical iOS developer. "Never support any user, who's device was purchased before last Friday." Yes, again this is for an app that is set to be for ONLY 4.1+ (hope that's the correct term). Check out my next image, you guys frickin' ROCK – Fattie May 18 '14 at 11:33
  • 1
    To answer your question "I believe, if you do NOT use a fragment, you can just extend "Activity" .. .is that right?" - For using backwards compatible Fragments instead of Activity you could extend from FragmentActivity and ActionBarActivity extends the FragmentActivity functionality with ActionBar support. – Patrick Leitermann May 18 '14 at 11:55
6

That will be my best guest. Devices with hardware button don't show the 3-dots menu.

Also if the project is 4.1+ you don't need neither support-v4 nor appcompat-v7. Those might be causing some conflict.

Link to Google explanation on buttons on different devices: http://developer.android.com/design/patterns/compatibility.html

Regarding using the build.gradle file or the dialog, well, probably yes, but I'm already used to the gradle file and never even look at the dialog, but I'm just old school.


Result!

enter image description here

Found Dirty Hack to force the overflow icon to be visible on devices which have the hardware menu button.

private void getOverflowMenu() {

     try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if(menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Source:http://www.tagwith.com/question_264107_overflow-menu-not-showed-at-action-bar

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
Budius
  • 39,391
  • 16
  • 102
  • 144
  • Amazing psychic call of the day Budius, thank you. It looks like (on a Mac - Studio anyway) (0.5.2, 5/2014) if the project IS only for 4.1+, it appears that if you DO add the two libraries, then oddly overflow simply does not work. (Meaning BOTH physical/icon do NOT work. It just shows how many can fit - and gives up.) By all means, I may have screwed up something else; but hope it helps someone. BTW the gray smudge on the left of this photo is a HTC phone (HTC guys, awesome looking phone, but get some frickin' LEDs??) – Fattie May 18 '14 at 11:41
0

I had similar problems showing action bar icons when starting to use Android Studio..

Strange that when I looked at the layout in the design screen it did showed the icons properly but when I tried to run the app both on actual device or on the emulator it showed 3 dots instead.

I do know that even on devices that have HW setting button I still see applications that shows action bar icons and not 3 dots.

Finally the only thing that helped was to do this: // compile 'com.android.support:appcompat-v7:21.0.0'

I comment this library dependency in the gradle that fixed the problem.

Moti Bartov
  • 3,454
  • 33
  • 42
0

I have the Something like this, when i moved my project to android studio, all action bar items instead if being displayed on the action bar, they only appear as text when pressing the hardware button menu, and when run on nexus, the three dots appear in the corner of the action bar !

i tried things suggested on this page, but had no success in showing the items on the action bar !

jack
  • 155
  • 5
  • 14