package com.examples.keys;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
public class MyActivity extends Activity {
MenuDialog menuDialog;
private class MenuDialog extends AlertDialog {
public MenuDialog(Context context) {
super(context);
View menu = getLayoutInflater().inflate(R.layout.custommenu, null);
setView(menu);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_MENU) {
dismiss();
return true;
}
return super.onKeyUp(keyCode, event);
}
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_MENU) {
if(menuDialog == null) {
menuDialog = new MenuDialog(this);
}
menuDialog.show();
return true;
}
return super.onKeyUp(keyCode, event);
}
}
//custommenu.xml
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_height="wrap_content" android:layout_weight="1"
android:src="@android:drawable/ic_menu_send" />
android:layout_height="wrap_content" android:layout_weight="1"
android:src="@android:drawable/ic_menu_save" />
android:layout_height="wrap_content" android:layout_weight="1"
android:src="@android:drawable/ic_menu_search" />
android:layout_height="wrap_content" android:layout_weight="1"
android:src="@android:drawable/ic_menu_preferences" />