目录搜索
androidManifestManifest.permissionManifest.permission_groupandroid.accessibilityserviceAccessibilityServiceandroid.accountsAccountandroid.appNotificationManagerandroid.bluetoothBluetoothAdapterBluetoothClassBluetoothClass.DeviceBluetoothClass.Device.MajorBluetoothClass.ServiceBluetoothDeviceBluetoothServerSocketBluetoothSocketandroid.contentSharedPreferencesandroid.database.sqliteSQLiteCursorDriverSQLiteOpenHelperandroid.graphicsBitmapandroid.locationLocationListenerGeocoderGpsStatusGpsStatus.ListenerGpsStatus.NmeaListenerGpsSatelliteandroid.mediaAudioFormatAsyncPlayerAudioRecordAudioRecord.OnRecordPositionUpdateListenerThumbnailUtilsAudioManagerandroid.netTrafficStatsMailToLocalSocketandroid.osAsyncTaskAsyncTask.StatusCountDownTimerMessageMessageQueueHandlerThreadandroid.textHtmlandroid.utilJsonWriterandroid.viewContextMenuContextMenu.ContextMenuInfoDisplayViewManagerViewViewStubViewTreeObserverViewParentWindowManagerGestureDetectorGravityMenuInflaterScaleGestureDetectorSoundEffectConstantsandroid.view.inputmethodInputConnectionInputMethodInputMethodSessionBaseInputConnectionInputMethodManagerandroid.widgetAbsListViewAbsListView.LayoutParamsAbsListView.OnScrollListenerAbsListView.RecyclerListenerAbsoluteLayoutAbsoluteLayout.LayoutParamsAbsSeekBarAbsSpinnerAdapterViewAdapterView.AdapterContextMenuInfoAdapterView.OnItemLongClickListenerAdapterView.OnItemSelectedListenerAdapterView.OnItemClickListenerAnalogClockBaseAdapterBaseExpandableListAdapterButtonCheckBoxCheckedTextViewCheckableChronometerChronometer.OnChronometerTickListenerCompoundButtonCompoundButton.OnCheckedChangeListenerCursorAdapterCursorTreeAdapterDatePickerDatePicker.OnDateChangedListenerDialerFilterDigitalClockEditTextFilterFilter.FilterListenerFilter.FilterResultsExpandableListAdapterExpandableListView.OnChildClickListenerExpandableListView.OnGroupClickListenerExpandableListView.OnGroupCollapseListenerExpandableListView.OnGroupExpandListenerFilterableGalleryGallery.LayoutParamsGridViewGridLayoutGridLayout.AlignmentRadioGroupImageViewImageView.ScaleTypeHorizontalScrollViewImageButtonImageSwitcherFilterQueryProviderListAdapterListViewMediaControllerMultiAutoCompleteTextViewMultiAutoCompleteTextView.CommaTokenizerMultiAutoCompleteTextView.TokenizerQuickContactBadgeRadioButtonRatingBarRatingBar.OnRatingBarChangeListenerRelativeLayoutRemoteViewsResourceCursorAdapterResourceCursorTreeAdapterScrollerScrollViewSearchViewSearchView.OnCloseListenerSearchView.OnQueryTextListenerSearchView.OnSuggestionListenerSeekBarSeekBar.OnSeekBarChangeListenerSimpleAdapterSimpleAdapter.ViewBinderSimpleCursorAdapterSimpleCursorAdapter.CursorToStringConverterSimpleCursorAdapter.ViewBinderSimpleCursorTreeAdapterSimpleCursorTreeAdapter.ViewBinderSimpleExpandableListAdapterSlidingDrawerSlidingDrawer.OnDrawerCloseListenerSlidingDrawer.OnDrawerOpenListenerSlidingDrawer.OnDrawerScrollListenerSpinnerSpinnerAdapterWrapperListAdapterTabHostTabHost.TabSpecTextViewTimePickerTimePicker.OnTimeChangedListenerToastTableLayoutTableLayout.LayoutParamsTableRowTableRow.LayoutParamsTabWidgetTextSwitcherToggleButtonTwoLineListItemVideoViewViewAnimatorViewFlipperViewSwitcherViewSwitcher.ViewFactoryZoomButtonsControllerZoomButtonsController.OnZoomListenerZoomButtonZoomControlsdalvik.systemDexFile
文字


MenuInflater

版本:Android 2.3 r1

结构

继承关系

public class MenuInflater extends Object

        

java.lang.Object

android.view.MenuInflater

子类及间接子类

直接子类

TabActivity

 

概述

这个类是用来实例化菜单XML文件成菜单对象。

由于性能的原因,由于程序创建时候就加载一些预处理XML文件,Menu过多就造成很重的负担。因此,这是目前无法在运行时使用多于一个XmlPullParserxml文件去使用MenuInflater,它只能使用一个XmlPullParser返回的编译过的资源(R.某些文件)

 

构造函数

         public MenuInflater (Context context)

构造填充(inflater)一个菜单

参见

getMenuInflater()

 

公共方法

         public void inflate (int menuRes, Menu menu)

菜单层次从一个指定的xml资源去填充,如果有错误会抛掷InflateException

参数

menuRes         要加载XML布局文件中的资源ID(例如R.menu.main_activity

menu       要填充的菜单,这些项目和子菜单就被添加到要填充菜单中

补充

文章精选

MenuInflater Android菜单从xml创建方法

         AndroidMenuInflater实例

         Android MenuInflater的使用(布局定义菜单)

示例代码

新建一个android2.2的项目,项目文件列表

MenuInfalterTest.java

public class MenuInflaterTest extends Activity {

    @Override

    public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

    }

 

    public boolean onCreateOptionsMenu(Menu menu) {

       // 获取当前的菜单

       MenuInflater inflater = getMenuInflater();

       // 填充菜单

       inflater.inflate(R.menu.option_menu, menu);

       return true;

    }

 

   

    public boolean onOptionsItemSelected(MenuItem item) {

       switch (item.getItemId()) {

       case R.id.menu_add:

           break;

       case R.id.menu_wallaper:

           break;

       case R.id.menu_search:

           break;

       case R.id.menu_setting:

           showSettings();

           break;

       }

       return super.onOptionsItemSelected(item);

    }

 

   

    private void showSettings() {

       Intent settings = new Intent

       (android.provider.Settings.ACTION_SETTINGS);

       settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK

              | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

       startActivity(settings);

    }

}

}

 

Main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="@string/hello"

    />

</LinearLayout>

 

Option_menu.xml

<?xml version="1.0" encoding="utf-8"?> 

<menu xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:id="@+id/menu_add" 

        android:title="Add" 

        android:icon="@android:drawable/ic_menu_add"/> 

     <item android:id="@+id/menu_wallaper" 

        android:title="Wallpaper" 

        android:icon="@android:drawable/ic_menu_gallery"/> 

    <item  android:id="@+id/menu_search" 

        android:title="Search" 

        android:icon="@android:drawable/ic_search_category_default"/> 

    <item  android:id="@+id/menu_setting" 

        android:title="Settings" 

      android:icon="@android:drawable/ic_menu_preferences"/>                             </menu> 

 


上一篇:下一篇: