Appcompat three dot menu not displayed on Android < 3 - android

I would like to display three dot menu in my app also on devices with android lower than version 3.0.
But on devices with Android version < 3 is menu displayed only after menu button pressing.
I tried to find any wotking solution for this but none from them working from me.
What is most easy way how to solve it on all devices?
Im using appCompat_v7_3
Many thanks for any advice.
Here is code of menu and activity.
menu main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/last_position_menu_btn"
android:icon="#drawable/ic_drawer"
android:title="#string/last_positions"
android:showAsAction="always"/>
<item android:id="#+id/settings_menu_btn"
android:icon="#drawable/ic_drawer"
android:title="#string/app_settings"
android:showAsAction="always"/>
</menu>
onCreateOptionMenu from main Activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
return super.onCreateOptionsMenu(menu);
}

Your 3.0 device has a hardware menu button. Android does not display the overflow icon when there is a hardware menu button present.
See this question or the documentation.

Related

Actionbar icon not showing despite showAsAction="always"

I'm trying to implement a menu in a ListActivity. Here's how I'm declaring the menu item:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/camera"
android:title="#string/camera_name"
android:icon="#drawable/cam"
app:showAsAction="always" />
</menu>
And this is what the preview shows in Android Studio:
The preview suggests everything is fine. It shows the camera icon that I put in the res/drawable folder.
Yet, when I try to run it in an emulator (Nexus 4 API 22), this is how the app shows up:
So the actual emulator is pushing the icon into the overflow menu despite being set as showAsAction="always".
This is how I am inflating the menu in the ListActivity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
Does anyone know what I'm doing wrong? Thanks in advance.
It is possibly because you have used app:showAsAction. So if you are using support library, simply add android:showAsAction beside app:showAsAction. This have to solve your problem.

Android onCreateOptionsMenu is not called

I am debugging on a Nexus, Android version 5.0
My Min SDK is 11, target SDK is 21.
I have the following XML
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/settings"
android:title="#string/settings_label"
app:showAsAction="ifRoom"/>
</menu>
And in my launcher activity I have this Java code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i("Inside onCreateOptionsMenu", "True");
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_start, menu);
return true;
}
However that Log line never makes it into LogCat, and my menu is never displayed.
My desired effect is to have an action bar with the 3 vertical dots which when clicked by the user will show my menu item.
You can go through the tutorial from several different providers as follows which are recommended by SO
Android Developer
Vogella
AndroidHive
All of them have great examples and source code to help you out

ActionBarSherlock menu item showing up on tablet not on phone

I am using ActionBarSherlock to create a menu (with the three dots) at the top and then have a few items as a submenu. The menu is showing up on tablets, but not on a four inch phone. The app can run on sdkVersion 9-17.
My menu.xml is:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_weather"
android:title="#string/weather"
android:icon="#drawable/weather_tab"/>
<item
android:id="#+id/menu_emergency"
android:title="#string/emergency_nums" />
<item
android:id="#+id/menu_suggest"
android:title="#string/friend" />
<item
android:id="#+id/menu_support"
android:title="#string/faq" />
<item
android:id="#+id/menu_about"
android:title="#string/about" />
</menu>
And I have a menu inflate of:
public boolean onCreateOptionsMenu(Menu menu)
{
getSupportMenuInflater().inflate(R.menu.menu, menu);
return true;
}
Thanks in advance for any help.
In your res/menu/menu.xml, your item can have a android:showAsAction parameter, which defines when to show them. You can then set a bunch of parameters that will help you displaying them (or not) more easily on phones and tablets. If you want to always show the menu item, just set this parameter to "always".
More here :
http://developer.android.com/guide/topics/resources/menu-resource.html
Try
public boolean onCreateOptionsMenu(Menu menu)
{
getSupportMenuInflater().inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
I kept searching and this is what finally worked for me: https://stackoverflow.com/a/11438245/2291915
I hope this can help someone else. I hadn't realized because I was using this on an emulator it was really about whether there was hard or soft buttons.

why I do not see my Icon in Android Option Menu?

I have the following code to generate a Menu Item:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu1"
android:icon="#drawable/ic_action1"
android:title="#string/foo" />
</menu>
I see the Item in the menu, but I can not see the icon. Whats wrong?
I dont want to use it as the following:
android:showAsAction="ifRoom|withText"
then I see the icon, but I dont want it to be in the Action Bar
When you are using the ActionBar / Holo theme, you won't see any menu item icons in the overflow menus, sorry.
I think you will get the old menu back when you apply a pre-Holo theme to your activity!
try something like this
onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.your_menu, menu);
menu.getItem(R.id.your_item_id).setIcon(R.drawable.your_drawable_id);
}

ActionBarSherlock + split action bar menu + items with "withText" doesn't show text. How to fix?

I'm using ActionBarSherlock and I'm trying to add an options menu to the ActionBar.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu_prev"
android:title="#string/menu_previous"
android:icon="#drawable/left_navigation"
android:showAsAction="always|withText" />
<item android:id="#+id/menu_next"
android:title="#string/menu_next"
android:icon="#drawable/right_navigation"
android:showAsAction="always|withText" />
</menu>
The icons are 32x32 pixels in the drawable-mdpi directory. When the ActionBar is split (portrait orientation), the icons show up but no text shows (plenty of room though). Long-pressing the icon Toasts the title. When the ActionBar is not split (landscape orientation), both the icons AND text show up as expected.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
Menu, MenuInflater, and getSupportMenuInflater() are all using the ActionBarSherlock implementations.
The 'Application' in the manifest declares:
android:uiOptions="splitActionBarWhenNarrow"
What can I do to make it show the title of each item when in portrait orientation?
Edit: Possibly relevant is that I'm running Android 4.0.4.
If you are using Android >= 3.0 ABS uses the system implementation of the actionbar, thus the behavior you see is correct. See #CommonsWare comment to the question as to why the behavior is that way.

Categories

Resources