This is how I implemented it on my Google GLASS:
First of all, implement in your Activity the menu as you would do it on a normal Android app:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection.
switch (item.getItemId()) {
case R.id.menu_item_1:
//Do what you want here
return true;
case R.id.menu_item_2:
//Do what you want here
return true;
case R.id.menu_item_3:
//Do what you want here
return true;
case R.id.menu_item_4:
//Do what you want here
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Then, implement the method onKeyDown, to make it open the menu when you are in the activity and you tap the touchpad:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
// Handle tap events.
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
//Play default tap sound
AudioManager audio = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audio.playSoundEffect(Sounds.TAP);
//Open the menu
openOptionsMenu();
return true;
default:
return super.onKeyDown(keyCode, event);
}
}
This is how your menu layout should look like:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_item_1"
android:title="@string/menu_item_1" />
<item
android:id="@+id/menu_item_2"
android:title="@string/menu_item_2"/>
<item
android:id="@+id/menu_item_3"
android:title="@string/menu_item_3"/>
<item
android:id="@+id/menu_item_4"
android:title="@string/menu_item_4"
android:icon="@drawable/menu_icon_4" />
</menu>
As you can see on item 4, you can also add icons to your menu.
Hope it helps :)