@kfrajer I found a code in a post yours on the last forum.
However it seemingly only worked on android mode version 3.0.2 and not on version 4.x
You said you would look in to that later. Did you get it working?
I have googled to try understand more of it.and found that the parameters of menu.add
are the following:
First:
The group ID – you can put items in a group and then make changes to the group. These changes will apply to all of the items in the group. This parameter is the ID of the group. We pass 0 for the groupId. Use Menu.NONE if the item should not be in a group.
Second:
The menu item ID – a unique ID to identify this menu item. We’ve defined a constant, MENU_ITEM which is initialized to the Menu class’s FIRST constant. We add 1 to MENU_ITEM for each successive item that we add to the menu
Third:
The order of appearance of the item in the menu. The order of the items is not important to us so we use the Menu.NONE constant, indicating that we don’t care about the order.
Fourth:
The resource ID of the string that will appear as the item’s name in the menu
The last one should be the Id of a string in the XML, but I have seen in many code snippets that a string may be passed directly.
What I do not understand is the use of the inflater, yet it will not inflate, meaning ‘link’ to a string value of a menu Id anyway.
The code does not give any error, but no menu will pop up.
Below I am posting a code as minimized as possible, just for the sake of oversight.
Do you have any idea how to go further?
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
void setup() {
fullScreen();
}
void draw() {
}
@ Override
void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(0, 1, Menu.NONE, "Red");
menu.add(0, 2, Menu.NONE, "Green");
menu.add(0, 3, Menu.NONE, "Blue");
super.onCreateOptionsMenu(menu, inflater);
}
@ Override
boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
background(255, 0, 0);
break;
case 2:
background(0, 255, 0);
break;
case 3:
background(0, 0, 255);
break;
}
return super.onOptionsItemSelected(item);
}
@ Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}