My activity has a menu that inflates on my emulator when I use its hardware "Menu" button, however when I run the app on my actual phone (Galaxy Nexus with 4.0.1) I cant work out a way to make the "3 dot" style menu button appear as it does in some apps. The way that I've implemented my menu is:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.wcoptions, menu);
return (super.onCreateOptionsMenu(menu));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.ooptions:
// open preferences activity
startActivity(new Intent(this, WorkCalcPreferenceActivity.class));
break;
case R.id.oquit:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
Also in my manifest file I have the minSDK set as 8 and the targetSDK set as 15.
This is my first app and Im still learning how to implement all these things so any help would be greatly appreciated :)
Edit: Here is menu.wcoptions
<item
android:id="#+id/ooptions"
android:icon="#drawable/ic_menu_settings"
android:title="Options"/>
<item
android:id="#+id/oquit"
android:icon="#drawable/ic_menu_exit"
android:title="Quit"/>
If you target Honeycomb or above you won't get the menu button. The menu button is only there for legacy purposes, and you should instead make use of the action bar or some other means of bringing up the menu.
Related
Well i read how change icons colors or add a button on navigation system bar like camera button.
But i want to know if i can add a button that open a especific apliccation like whatsApp or anyone installed like a shortcut.
Very simple, in an activity, override onOptionsItemSelected method. Then test the menu item which is clicked and open the application you want to using an Intent.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.MENU_ID:
Intent i = new Intent();
i.setFlags(...);
startActivity(i);
break;
}
return super.onOptionsItemSelected(item);
}
All what you need you can find here
You can open another application from your onClick or onOptionsItemSelected event.
After couple of hours of investigations and trying to find a solution I’ve decided to write here my problem in idea that maybe someone else face it also and found a fix for it.
I have a application with a menu, one of the options being a Share option, declare like this in menu xml file:
<item android:id="#+id/menu_share"
android:actionProviderClass="android.widget.ShareActionProvider"
android:title="Share"/>
In onOptionsItemSelected method I create and set the share intent:
private ShareActionProvider shareActionProvider;
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_share:
MenuItem actionItem = optionsMenu.findItem(R.id.menu_share);
shareActionProvider = (ShareActionProvider) actionItem.getActionProvider();
shareActionProvider.setShareIntent(createShareIntent());
return true;
default:
return super.onOptionsItemSelected(item);
}
}
When pressing the Share menu option the list with apps to share is displayed.
What I want is when I rotate the device that list to be visible, but instead is disappearing. To mention that I can’t use android:configChanges in order to prevent the activity from being recreated.
I wanted first to see how can I open that share apps list programmatically.
a). Calling the below method nothing visual happens; it just updates the ShareActionProvider
public void showShareItemList() {
MenuItem actionItem = optionsMenu.findItem(R.id.menu_share);
shareActionProvider = (ShareActionProvider) actionItem.getActionProvider();
shareActionProvider.setShareIntent(createShareIntent());
}
b). Calling the below method opens a new activity – but not a menu options list like in the picture above.
public void showShareItemList2(){
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
startActivity(Intent.createChooser(sharingIntent, "Share"));
}
Result:
c).The below method just opens the menu option:
public void showShareItemList3() {
openOptionsMenu(); // programmatically open the options menu
}
So, is there a way to open the share item list of applications programmatically ? Or at least is there a way to press menu key programmatically ( = programatically select a menu item)?
Another issue is how can I know if the share list is visible on orientation changed?
For this I’m using a boolean variable private boolean isShareOptionMenuListVisible = false; which I save it on method onSaveInstanceState() and restored it in onCreate() method.
I make isShareOptionMenuListVisible = true when the Share item is pressed, but I could not find a way to make it to false when is not visible anymore.
Using the override method onOptionsMenuClosed is not helping me because this “is called whenever the options menu is being closed” (this is in documentation, even if I can say this is not real because in my app is never called), and I want to know when the Share apps options menu is being closed.
Here is a sample documented project which demonstrates all the above issues: project link.
Any help is welcome! Thanks.
If you're using SDK 11 or above, you can register to receive a callback when the (or any) action item's menu is showing, including your ShareActionProvider:
getActionBar().addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() {
#Override
public void onMenuVisibilityChanged(boolean isVisible) {
...
}
});
This method is also supported in ActionBarSherlock, but for some reason the listener is never actually called.
I am Working on One Application which has Settings Screen which Opens When User Click on OptionMenu Shortcut which shows on Devices as Default Button or any other Sign.
it Works fine when there is default menu button in device but not getting any Sign for Menu Option when there is not any default menu button in devices.
My Code is as Below:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_setting, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.btnSettingMenu:
Intent intent = new Intent(MainActivity.this,
RegisterActivity.class);
intent.putExtra("From", "MainActivity");
startActivity(intent);
break;
default:
break;
}
return true;
}
I have refered to Link HERE but could not able to solve my problem.
Point I would like to add is: I am getting the Menu Option in Emulator when i am pressing PageUp or F2.
But when the Device Does not have Default Menu Button it is not Showing with any other indication as three dots or some other way.
My Question : How can User Go to my Setting Screen if he is not Finding Option Menu Sign in real devices Like Nexus 7?
Thanks in Advance.
For showing Menu icon in above 4.0 Devices:
if you have declared android:targetSdkVersion="xx"
Either remove it if you don't required.
OR
If you want to declare it,then set value 0f xx below 14
i.e.android:targetSdkVersion="13".
Hope it will work for you.
Try this:
Please remove this two line in your java class.
// hide titlebar of application
// must be before setting the layout
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hide statusbar of Android
// could also be done later
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Please remove this two line in your AndroidManifest.xml.
To hide the titlebar of your application you can use the predefined style
android:theme=”#android:style/Theme.NoTitleBar”.
or if you also want to hide the statusbar of your application use
android:theme=”#android:style/Theme.NoTitleBar.Fullscreen”.
This morning I came across a problem in the Android OS. I have just created an image show application. My application has some functions in a menu in which there are two buttons. The first is a home button and the second is a bookmark button.
When i run my app in an android phone, it works OK and I can easily find the menu buttons, but when I run it on a Galaxy Tab, I am unable to find the menu buttons.
How can I get my menu buttons working in Galaxy Tab?
Here is my code:
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_bookmark:
db.updateContact(new Contact(itemN,imageStatus));
return true;
case R.id.home_page:
Intent i = new Intent(imageTouchs.this, Comics.class);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu, menu);
return true;
}
Say Goodbye to the Menu Button
If you’ve already developed an app to support Android 2.3 and lower, then you might have noticed that when it runs on a device without a hardware Menu button (such as a Honeycomb tablet or Galaxy Nexus), the system adds the action overflow button beside the system navigation.
Apologies for what I am sure is a common question, but after Googling for a while it seems I don't know the proper Android term for what I want and so am stuck.
I would like to know how to work with the main pop-up menu associated with a view...that is, if you are sitting at some activity doing nothing and press the menu key on the phone, how to work with that menu that commonly opens on many apps containing "Settings", "Exit", etc.
I am not sure what this is called, but if someone can point me to the appropriate portion of the SDK, that would be appreciated. Also, if someone knows how to work this menu within the context of the Eclipse ADT plugin, that'd be great, too.
Cheers.
As CaseyB says, it's just called a menu.
For a quick start on using it, you could create a subfolder in the res folder of an eclipse project and call it "menu" add in some xml for the view, and the call a MenuInflator from the onCreateOptionsMenu function.
Ok, that might be a bit confusing, so i've included some sample code that should get you started. This code should make it so when you press the menu button you can select one of two new activities to get loaded.
In Main Activity add:
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
// Define whatever other activities you can to load in here or whatever.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.info:
startActivity(new Intent(this, Info.class));
break;
case R.id.logs:
startActivity(new Intent(this, Logs.class));
break;
}
return true;
}
menu.xml file: Link to whatever icon images you want.
<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<!-- Copyright © 2012 Tutela Technologies Ltd. -->
<!-- All Rights Reserved. -->
<!-- -->
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/info"
android:icon="#drawable/ic_menu_info_details"
android:title="Info"></item>
<item
android:id="#+id/logs"
android:icon="#drawable/ic_menu_report_image"
android:title="Logs"></item>
</menu>
Then in your AndroidManifest.xml make sure you remember to add in the new activities.
<activity
android:name="com.whatever.Gui.Info"
android:label="#string/appTitle">
</activity>
<activity
android:name="com.whatever.Gui.Logs"
android:label="#string/appTitle">
</activity>
Note: in this example the labels are defined in strings.xml
<string name="appTitle">Your App name</string>
Hope this helps you!
Cheers
It's just called the menu. Here is a tutorial to get you started. Things get a little weird in 3.0+ but once you get the basics down it shouldn't be too hard to pick up.
On versions prior to 3.0, these are menus. Menus are being replaced by the ActionBar in the more recent versions of Android.
About menus: http://developer.android.com/guide/topics/ui/menus.html
Tutorial about menus: http://www.androidhive.info/2011/09/how-to-create-android-menus/
Look at the example:
Activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.SettingsMenuItem:
startActivity(new Intent(this, SettingsActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
In xml: (in /res/menu/menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/SettingsMenuItem"
android:icon="#drawable/settings"
android:title="#string/settings"/>
</menu>