读书人

Android自定义menu菜单要领

发布时间: 2012-08-09 15:59:21 作者: rapoo

Android自定义menu菜单要点

?? step 1

?? public boolean onCreateOptionsMenu(Menu menu) {
??? ??? menu.add("xxxx");// 必须创建一项
??? ??? return super.onCreateOptionsMenu(menu);
??? }

?

??? step2

??? public boolean onMenuOpened(int featureId, Menu menu) {

????? ? //以下实现自定义的样式
??? ??? LayoutInflater factory = LayoutInflater.from(this);
??????? final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
??????? new AlertDialog.Builder(OCNBrowserActivity.this)
??????????? .setIconAttribute(android.R.attr.alertDialogIcon)
??????????? .setTitle(R.string.app_name)
??????????? .setView(textEntryView)
??????????? .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
??????????????? public void onClick(DialogInterface dialog, int whichButton) {
??????????????? ??? EditText editText = (EditText)textEntryView.findViewById(R.id.url_edit);
??????????????? ??? mWebView.loadUrl(editText.getText().toString());
??????????????? }
??????????? })
??????????? .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
??????????????? public void onClick(DialogInterface dialog, int whichButton) {

??????????????????? /* User clicked cancel so do some stuff */
??????????????? ???
??????????????? }
??????????? })
??????????? .create().show();
??????? return false;??? ??? // 此处必须返回false
??? }

读书人网 >Android

热点推荐