Java 类android.support.annotation.MenuRes 实例源码

项目:Hitalk    文件:FloatingSearchView.java   
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
项目:JsoupSample    文件:MainPresenterImpl.java   
@Override
public void switchId(@MenuRes int id) {
    switch (id) {
        case R.id.dytt:
        case FIRST_FRAGMENT:
            setSelectFragment(TYPE_DYTT_FRAGMENT);
            break;
        case R.id.dy_2018:
            setSelectFragment(TYPE_DY2018_FRAGMENT);
            break;
        case R.id.xiaopian:
            setSelectFragment(TYPE_XP_FRAGMENT);
            break;
        case R.id.piaohua:
            setSelectFragment(TYPE_PH_FRAGMENT);
            break;
        case R.id.k567:
            setSelectFragment(TYPE_K567_FRAGMENT);
            break;
    }
}
项目:JsoupSample    文件:MainPresenterImpl.java   
@Override
public void switchId(@MenuRes int id) {
    switch (id) {
        case R.id.search:
            view.switchSearch();
            break;
        case R.id.mark:
            view.switchMark();
            break;
        case FIRST_FRAGMENT:
        case R.id.fiction_81:
            setSelectFragment(TYPE_ZW_FRAGMENT);
            break;
        case R.id.bi_qu_ge:
            setSelectFragment(TYPE_BGQ_FRAGMENT);
            break;
        case R.id.ksw:
            setSelectFragment(TYPE_KSW_FRAGMENT);
            break;
        case R.id.piao_tian:
            setSelectFragment(TYPE_PT_FRAGMENT);
            break;
    }
}
项目:JsoupSample    文件:MainPresenterImpl.java   
@Override
public void switchId(@MenuRes int id) {
    switch (id) {
        case R.id.mzitu:
            setSelectFragment(TYPE_MZT_FRAGMENT);
            break;
        case FIRST_FRAGMENT:
        case R.id.dbmz:
            setSelectFragment(TYPE_DB_FRAGMENT);
            break;
        case R.id.mm:
            setSelectFragment(TYPE_MM_FRAGMENT);
            break;
        case R.id.meizitu:
            setSelectFragment(TYPE_MEIZITU_FRAGMENT);
            break;
        case R.id.kk:
            setSelectFragment(TYPE_KK_FRAGMENT);
            break;
        case R.id.collection:
            setSelectFragment(TYPE_COLLECTION_FRAGMENT);
            break;
        case R.id.search:
            view.switchSearch();
    }
}
项目:GComic    文件:FloatingSearchView.java   
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes == 0) return;
    getActivity().getMenuInflater()
                 .inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
项目:SublimeNavigationView    文件:SublimeNavigationView.java   
/**
 * Provides a mechanism for switching between any number of Menus.
 *
 * @param newMenuResId id of the menu that you wish
 *                     to switch to. Eg: R.menu.new_menu_id
 */
public void switchMenuTo(@MenuRes int newMenuResId) {
    if (newMenuResId < 1) {
        Log.e(TAG, "Could not switch to new menu: passed menuResourceId was invalid.");
        return;
    }

    mMenu = new SublimeMenu(newMenuResId);
    inflateMenu(newMenuResId);

    mMenu.setCallback(new SublimeMenu.Callback() {
        public boolean onMenuItemSelected(SublimeMenu menu, SublimeBaseMenuItem item,
                                          OnNavigationMenuEventListener.Event event) {
            return SublimeNavigationView.this.mEventListener != null
                    && SublimeNavigationView.this
                    .mEventListener.onNavigationMenuEvent(event, item);
        }
    });

    mMenu.setMenuPresenter(getContext(), mPresenter);
}
项目:FloatingSearchView    文件:FloatingSearchView.java   
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
项目:material-components-android    文件:TestUtilsActions.java   
/**
 * Clears and inflates the menu.
 *
 * @param menuResId The menu resource XML to be used.
 */
public static ViewAction reinflateMenu(final @MenuRes int menuResId) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(NavigationView.class);
    }

    @Override
    public String getDescription() {
      return "clear and inflate menu " + menuResId;
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();
      final NavigationView nv = (NavigationView) view;
      nv.getMenu().clear();
      nv.inflateMenu(menuResId);
      uiController.loopMainThreadUntilIdle();
    }
  };
}
项目:FloatingSearchView    文件:FloatingSearchView.java   
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
项目:android_maplibui    文件:BottomToolbar.java   
@Override
public void inflateMenu(@MenuRes int resId) {
    super.inflateMenu(resId);
    Menu menu = getMenu();
    MenuItem item = menu.getItem(0);
    int size = item.getIcon().getIntrinsicWidth() + ControlHelper.dpToPx(30, getResources());
    int width = getWidth();

    for (int i = 0; i < menu.size(); i++) {
        item = menu.getItem(i);
        if (size * (i + 2) < width)
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        else
            break;
    }
}
项目:MaterialMasterDetail    文件:CustomAppBar.java   
public void setMenuRes(@MenuRes int menuGeneral, @MenuRes int menuSpecific, @MenuRes int menuMerged) {
    toolbarSpecific.getMenu().clear();
    if (toolbarGeneral != null) {
        toolbarGeneral.getMenu().clear();
        toolbarGeneral.inflateMenu(menuGeneral);
        toolbarSpecific.inflateMenu(menuSpecific);
    } else {
        toolbarSpecific.inflateMenu(menuMerged);
    }
}
项目:IslamicLibraryAndroid    文件:BooksCollection.java   
@MenuRes
public int getMoreMenuRes() {
    if (isAutomatic()) {
        return R.menu.automatic_collection;
    } else {
        if (!isFavourie()) {
            return R.menu.user_collection;
        } else {
            return R.menu.favourite_collection;
        }
    }
}
项目:fluentAppBar    文件:MenuSecondaryItemsAdapter.java   
MenuSecondaryItemsAdapter(Context context, @MenuRes int secondaryMenuId, View.OnClickListener onClickListener,
                                 @ColorInt int foregroundColour) {
    this.context = context;
    this.onClickListener = onClickListener;
    this.foregroundColour = foregroundColour;
    this.itemss = new ArrayList<>();

    MenuParserHelper.parseMenu(context, secondaryMenuId, itemss);
}
项目:fluentAppBar    文件:FluentAppBar.java   
public void setNavigationMenu(@MenuRes int menuRes, OnClickListener onClickListener) {
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.nav_items_recycler);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
    menuNavigationItemsAdapter = new MenuNavigationItemsAdapter(getContext(), menuRes, onClickListener,
            foregroundColour);
    recyclerView.setAdapter(menuNavigationItemsAdapter);
}
项目:fluentAppBar    文件:FluentAppBar.java   
public void setSecondaryMenu(@MenuRes int menuRes, OnClickListener onClickListener) {
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.secondary_menu_items_recyler);
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    menuSecondaryItemsAdapter = new MenuSecondaryItemsAdapter(getContext(), menuRes, onClickListener,
            foregroundColour);
    recyclerView.setAdapter(menuSecondaryItemsAdapter);
}
项目:fluentAppBar    文件:MenuParserHelper.java   
public static void parseMenu(Context context, @MenuRes int menuRes, List<MenuEntry> menuEntryList){
    PopupMenu p = new PopupMenu(context, null);
    Menu menu = p.getMenu();
    new MenuInflater(context).inflate(menuRes, menu);

    for (int i = 0; i < menu.size(); i++) {
        android.view.MenuItem item = menu.getItem(i);
        menuEntryList.add(new MenuEntry(item.getTitle().toString(), item.getIcon(), item.getItemId()));
    }
}
项目:fluentAppBar    文件:MenuNavigationItemsAdapter.java   
MenuNavigationItemsAdapter(Context context, @MenuRes int menuRes, View.OnClickListener onClickListener,
                                  @ColorInt int foregroundColour) {
    this.context = context;
    this.onClickListener = onClickListener;
    this.foregroundColour = foregroundColour;
    this.navItems = new ArrayList<>();

    populateNavigationItems(menuRes);
}
项目:ChromeLikeTabSwitcher    文件:TabSwitcherModel.java   
@Override
public final void inflateToolbarMenu(@MenuRes final int resourceId,
                                     @Nullable final OnMenuItemClickListener listener) {
    this.toolbarMenuId = resourceId;
    this.toolbarMenuItemListener = listener;
    notifyOnToolbarMenuInflated(resourceId, listener);
}
项目:QuickActionView    文件:QuickActionView.java   
/**
 * Add actions to the QuickActionView from the given menu resource id.
 *
 * @param menuId menu resource id
 * @return the QuickActionView
 */
public QuickActionView addActions(@MenuRes int menuId) {
    Menu menu = new MenuBuilder(mContext);
    new MenuInflater(mContext).inflate(menuId, menu);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        Action action = new Action(item.getItemId(), item.getIcon(), item.getTitle());
        addAction(action);
    }
    return this;
}
项目:NeoTerm    文件:TabSwitcherModel.java   
@Override
public final void inflateToolbarMenu(@MenuRes final int resourceId,
                                     @Nullable final OnMenuItemClickListener listener) {
    this.toolbarMenuId = resourceId;
    this.toolbarMenuItemListener = listener;
    notifyOnToolbarMenuInflated(resourceId, listener);
}
项目:Material-BottomNavigation    文件:BottomNavigation.java   
/**
 * Inflate a menu resource into this navigation component
 *
 * @param menuResId the menu resource id
 */
public void inflateMenu(@MenuRes final int menuResId) {
    defaultSelectedIndex = 0;
    if (isAttachedToWindow()) {
        setItems(MenuParser.inflateMenu(getContext(), menuResId));
        pendingMenu = null;
    } else {
        pendingMenu = MenuParser.inflateMenu(getContext(), menuResId);
    }
}
项目:AndroidSweetSheet-master    文件:SweetSheet.java   
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
项目:MoonlightNote    文件:MenuUtils.java   
/**
 * 显示Popup菜单
 *
 * @param context  上下文
 * @param v        视图
 * @param menu     菜单资源文件
 * @param listener 菜单项目点击监听器
 */
public static void showPopupMenu(@NonNull Context context, @NonNull View v, @MenuRes int menu,
                                 @NonNull PopupMenu.OnMenuItemClickListener listener) {
    //新建PopupMenu对像
    PopupMenu popupMenu = new PopupMenu(context, v);
    //生成Menu视图
    popupMenu.getMenuInflater().inflate(menu, popupMenu.getMenu());
    //setOnMenuItemClickListener
    popupMenu.setOnMenuItemClickListener(listener);
    //显示PopupMenu
    popupMenu.show();
}
项目:CycleMenu    文件:CycleMenuWidget.java   
/**
 * Set the menu items from the menu res.
 *
 * @param menuResId menu resource from which need to get menuItems and add to the cycleMenu
 */
public void setMenuRes(@MenuRes int menuResId) {
    mInitialized = false;
    Menu menu = new MenuBuilder(getContext());
    MenuInflater inflater = new MenuInflater(getContext());
    inflater.inflate(menuResId, menu);
    setMenu(menu);
}
项目:FABRevealMenu-master    文件:FABRevealMenu.java   
/**
 * Set menu from menu xml
 *
 * @param menuRes menu xml resource
 */
public void setMenu(@MenuRes int menuRes) {
    mCustomView = null;
    mMenuRes = menuRes;
    removeAllViews();
    @SuppressLint("RestrictedApi")
    Menu menu = new MenuBuilder(getContext());
    new MenuInflater(getContext()).inflate(menuRes, menu);
    setUpMenu(menu);
}
项目:Bottom-sheet-Listview    文件:MenuSheetView.java   
/**
 * Inflates a menu resource into the menu backing this sheet.
 *
 * @param menuRes Menu resource ID
 */
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes != -1) {
        MenuInflater inflater = new MenuInflater(getContext());
        inflater.inflate(menuRes, menu);
    }

    prepareMenuItems();
}
项目:Mysplash    文件:ThemeManager.java   
public static void inflateMenu(Toolbar toolbar,
                               @MenuRes int lightResId, @MenuRes int darkResId) {
    if (getInstance(toolbar.getContext()).isLightTheme()) {
        toolbar.inflateMenu(lightResId);
    } else {
        toolbar.inflateMenu(darkResId);
    }
}
项目:MousePaintYzz    文件:SweetSheet.java   
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
项目:MaterialDrawer    文件:DrawerBuilder.java   
/**
 * Inflates the DrawerItems from a menu.xml
 *
 * @param menuRes
 * @return
 */
public DrawerBuilder inflateMenu(@MenuRes int menuRes) {
    MenuInflater menuInflater = new SupportMenuInflater(mActivity);
    MenuBuilder mMenu = new MenuBuilder(mActivity);

    menuInflater.inflate(menuRes, mMenu);

    addMenuItems(mMenu, false);

    return this;
}
项目:YouJoin-Android    文件:DrawerBuilder.java   
/**
 * Inflates the DrawerItems from a menu.xml
 *
 * @param menuRes
 * @return
 */
public DrawerBuilder inflateMenu(@MenuRes int menuRes) {
    MenuInflater menuInflater = new SupportMenuInflater(mActivity);
    MenuBuilder mMenu = new MenuBuilder(mActivity);

    menuInflater.inflate(menuRes, mMenu);

    addMenuItems(mMenu, false);

    return this;
}
项目:Climb    文件:ToolbarFragment.java   
/**
     * @param title 标题
     * @param menu 菜单
     */
    public void setupToolbar(String title, @MenuRes int menu) {

        mToolbar.setTitle(title);
        mToolbar.inflateMenu(menu);
        mToolbar.setOnMenuItemClickListener(this);
        mToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_menu_white));
        mToolbar.setNavigationOnClickListener(v -> {
            OldDriver.getIns().post(new OpenDrawerEvent());
        });
//        ((AppCompatActivity)mActivity).setSupportActionBar(mToolbar);
//        ((AppCompatActivity)mActivity).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    }
项目:ThreePhasesBottomSheet    文件:MenuSheetView.java   
/**
 * Inflates a menu resource into the menu backing this sheet.
 *
 * @param menuRes Menu resource ID
 */
public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes != -1) {
        MenuInflater inflater = new MenuInflater(getContext());
        inflater.inflate(menuRes, menu);
    }

    prepareMenuItems();
}
项目:XanderPanel    文件:XanderPanel.java   
public Builder setMenu(@MenuRes int xmlRes, PanelInterface.PanelMenuListener menuListener) {
    if (null == mPanelParams.actionMenu) {
        mPanelParams.actionMenu = new ActionMenu(mContext);
    }
    (new MenuInflater(mContext)).inflate(xmlRes, mPanelParams.actionMenu);
    mPanelParams.menuListener = menuListener;
    return this;
}
项目:RecyclerExt    文件:MenuViewHolder.java   
/**
 * Shows the menu specified with the <code>menuResourceId</code> starting
 * at the <code>anchor</code>
 *
 * @param anchor The view to show the popup menu from
 * @param menuResourceId The resource id for the menu to show
 */
protected void showMenu(@NonNull View anchor, @MenuRes int menuResourceId) {
    PopupMenu menu = new PopupMenu(anchor.getContext(), anchor);
    MenuInflater inflater = menu.getMenuInflater();
    inflater.inflate(menuResourceId, menu.getMenu());

    onPreparePopupMenu(menu.getMenu());
    menu.setOnMenuItemClickListener(this);
    menu.show();
}
项目:AndroidSweetSheet    文件:SweetSheet.java   
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
项目:MousePaint    文件:SweetSheet.java   
public void setMenuList(@MenuRes int menuRes) {

        Menu menu = new PopupMenu(mParentVG.getContext(), null).getMenu();
        new MenuInflater(mParentVG.getContext()).inflate(menuRes, menu);
        List<MenuEntity> menuEntities = getMenuEntityFormMenuRes(menu);

        if(mDelegate != null) {

            mDelegate.setMenuList(menuEntities);
        }else{
            mMenuEntities=menuEntities;
        }

    }
项目:trekarta    文件:PanelMenuFragment.java   
public void setMenu(@MenuRes int menuId, OnPrepareMenuListener onPrepareMenuListener) {
    mMenuId = menuId;
    mOnPrepareMenuListener = onPrepareMenuListener;
    if (isVisible()) {
        populateMenu();
        mAdapter.notifyDataSetChanged();
    }
}
项目:vuze-remote-for-android    文件:SideActionsAdapter.java   
public SideActionsAdapter(Context context, String remoteProfileID,
        @MenuRes int menuRes, @Nullable int[] restrictToMenuIDs,
    SideActionSelectionListener selector) {
    super(selector);
    this.context = context;
    this.remoteProfileID = remoteProfileID;
    this.restrictToMenuIDs = restrictToMenuIDs;
    this.selector = selector;
    setHasStableIds(true);

    menuBuilder = new MenuBuilder(context);
    new MenuInflater(context).inflate(menuRes, menuBuilder);

    updateMenuItems();
}
项目:material-cab    文件:MaterialCab.java   
@UiThread
public MaterialCab menu(@MenuRes int menuRes) {
  menu = menuRes;
  if (toolbar != null) {
    if (toolbar.getMenu() != null) {
      toolbar.getMenu().clear();
    }
    if (menuRes != 0) {
      toolbar.inflateMenu(menuRes);
    }
    toolbar.setOnMenuItemClickListener(this);
  }
  return this;
}
项目:MaterialDrawer-Xamarin    文件:DrawerBuilder.java   
/**
 * Inflates the DrawerItems from a menu.xml
 *
 * @param menuRes
 * @return
 */
public DrawerBuilder inflateMenu(@MenuRes int menuRes) {
    MenuInflater menuInflater = new SupportMenuInflater(mActivity);
    MenuBuilder mMenu = new MenuBuilder(mActivity);

    menuInflater.inflate(menuRes, mMenu);

    addMenuItems(mMenu, false);

    return this;
}