Android menu overflow Android ActionBar not showing on sdk 10

We welcome you and thank you for reading this question.

I am trying to develop an Android application that will use the ActionBar compatibility library. I followed (as far as I can see) all the recommendations when using the compatibility library. My manifest looks like this (only relevant code):

<?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 used Theme.AppCompat theme as recommended.

My menu file is as follows:

 <?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 use 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 the device and on the emulator, the overflow menus (three dots to the right of the action bar) are not displayed. Only the first 2 menu items are displayed on the action bar. If I press the Menu button on the device, the third item will appear in the lower left corner of the screen (not in the upper right corner, as on devices with later versions of Android). The same code works well on android sdk 17 on the emulator (the overflow menu is displayed with the corresponding actions).

I searched the Internet for a solution, but could not find it with this particular problem. I would have avoided this problem if I hadn’t installed applications on an Android 2.3.3 device that have the same action bar and that show an overflow menu icon and work properly, like on any last Android device. One example of this application is the todoist application ( https://en.todoist.com/android ) or the processing application ( https://play.google.com/store/apps/details?id=com.handcent.nextsms&hl= en ) that both behave well on this device.

Is there anything I can't see, or is there an alternative solution for the recommended way to use compatibility with the program?

Thank you for your time.

+6
source share
3 answers

@Andrei Google disabled the menu overflow button in appcompat on pre honycomb. If you really want to add it, go to the android github repository and download platform_frameworks_support. It contains sorce for appcompat in platform_framework_support_master / v7 / appcompat.

Create the libs folder inside appcompat and put the latest version of android-v4.jar support. Now open the file v7/appcompat/src/android/support/v7/internal/view/ActionBarPolicy.java . You will see that showOverflowMenuButton returns false for pre honycomb. Just return it true and add the edited appcompat as a library to your project and you won’t need any custom overflow button. This worked for me. sorry for my English

EDIT: valid 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; } 
+7
source

Try to show me how.

I add the 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 the menu button by clicking in the action to display this menu (the solution from Opening the submenu in the action bar on the Equipment 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 2.2 is as follows:

Android 2.2 Overflow menu

Hope this helps you.

+5
source

I finally found the answer for this situation.

All you have to do is call the following in OnCreate in your activity.

 ActionBarPolicy.get(this).showsOverflowMenuButton(); 
-1
source

Source: https://habr.com/ru/post/959115/


All Articles