本文整理汇总了Java中android.support.annotation.MenuRes类的典型用法代码示例。如果您正苦于以下问题:Java MenuRes类的具体用法?Java MenuRes怎么用?Java MenuRes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MenuRes类属于android.support.annotation包,在下文中一共展示了MenuRes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inflateMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
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();
}
}
示例2: switchId
import android.support.annotation.MenuRes; //导入依赖的package包/类
@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;
}
}
示例3: switchId
import android.support.annotation.MenuRes; //导入依赖的package包/类
@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;
}
}
示例4: switchId
import android.support.annotation.MenuRes; //导入依赖的package包/类
@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();
}
}
示例5: inflateMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
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();
}
}
示例6: switchMenuTo
import android.support.annotation.MenuRes; //导入依赖的package包/类
/**
* 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);
}
示例7: reinflateMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
/**
* 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();
}
};
}
示例8: inflateMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
@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;
}
}
示例9: setMenuRes
import android.support.annotation.MenuRes; //导入依赖的package包/类
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);
}
}
示例10: getMoreMenuRes
import android.support.annotation.MenuRes; //导入依赖的package包/类
@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;
}
}
}
示例11: MenuSecondaryItemsAdapter
import android.support.annotation.MenuRes; //导入依赖的package包/类
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);
}
示例12: setNavigationMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
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);
}
示例13: setSecondaryMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
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);
}
示例14: parseMenu
import android.support.annotation.MenuRes; //导入依赖的package包/类
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()));
}
}
示例15: MenuNavigationItemsAdapter
import android.support.annotation.MenuRes; //导入依赖的package包/类
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);
}