res/layout/custommenu.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageButton android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:contentDescription="@string/app_name" android:src="@android:drawable/ic_menu_send" /> <ImageButton android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:contentDescription="@string/app_name" android:src="@android:drawable/ic_menu_save" /> <ImageButton android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:contentDescription="@string/app_name" android:src="@android:drawable/ic_menu_search" /> <ImageButton android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" android:contentDescription="@string/app_name" android:src="@android:drawable/ic_menu_preferences" /> </LinearLayout>
Activity
package com.sqlendia.android; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; public class Android2_22Activity extends Activity { MenuDialog menuDialog; public class MenuDialog extends AlertDialog { public MenuDialog(Context context) { super(context); setTitle("Menu"); 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 || keyCode == KeyEvent.KEYCODE_BACK) { if (menuDialog == null) { menuDialog = new MenuDialog(this); } menuDialog.show(); return true; } return super.onKeyUp(keyCode, event); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
0 件のコメント:
コメントを投稿