本文整理匯總了Java中android.support.v4.view.MenuItemCompat.setShowAsAction方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuItemCompat.setShowAsAction方法的具體用法?Java MenuItemCompat.setShowAsAction怎麽用?Java MenuItemCompat.setShowAsAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.view.MenuItemCompat
的用法示例。
在下文中一共展示了MenuItemCompat.setShowAsAction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
MenuItem item = menu.add(R.string.search);
if (ThemeManager.getInstance().isLightBackground())
item.setIcon(R.drawable.ic_search_black_24dp);
else
item.setIcon(R.drawable.ic_search_white_24dp);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS
| MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView = new CustomSearchView(this);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true);
MenuItemCompat.setActionView(item, searchView);
return true;
}
示例2: onPrepareOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.clear();
menu.add(0, mItemBaseID, 1, R.string.sort)
.setIcon(ThemeManager.getInstance().isLightBackground() ? R.drawable.ic_sort_black_24dp : R.drawable.ic_sort_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(0, mItemBaseID + 1, 2, R.string.clear)
.setIcon(ThemeManager.getInstance().isLightBackground() ? R.drawable.ic_delete_black_24dp : R.drawable.ic_delete_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
MenuItem item = menu.add("Search History");
item.setIcon(ThemeManager.getInstance().isLightBackground() ? R.drawable.ic_search_black_24dp : R.drawable.ic_search_white_24dp);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
| MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
mSearchView = new HistorySearchView(getActivity());
mSearchView.setOnQueryTextListener(this);
mSearchView.setOnCloseListener(this);
mSearchView.setIconifiedByDefault(true);
MenuItemCompat.setActionView(item, mSearchView);
}
示例3: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
/**
* Create menu items such as "delete" button
* @param menu The menu
* @return
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuItem deleteItem = menu.add(
Menu.NONE, DELETE_BUTTON_ID, Menu.NONE, "Delete");
MenuItemCompat.setShowAsAction(
deleteItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
deleteItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
confirmDelete();
return true;
}
});
return true;
}
示例4: onPrepareOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public void onPrepareOptionsMenu(Menu menu) {
menu.clear();
// Place an action bar item for searching.
MenuItem item = menu.add(R.string.search);
if (ThemeManager.getInstance().isLightBackground())
item.setIcon(R.drawable.ic_search_black_24dp);
else
item.setIcon(R.drawable.ic_search_white_24dp);
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
| MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
mSearchView = new MySearchView(getActivity());
mSearchView.setOnQueryTextListener(this);
mSearchView.setOnCloseListener(this);
mSearchView.setIconifiedByDefault(true);
MenuItemCompat.setActionView(item, mSearchView);
//menu.add(Menu.NONE, mItemBaseID, 0, R.string.open).setIcon(ThemeManager.getInstance().getCurrentTheme() == ThemeType.Light ? R.drawable.open_light : R.drawable.open_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, mItemBaseID + 1, 1, R.string.sort)
.setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_sort_by_alpha_black_24dp : R.drawable.ic_sort_by_alpha_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
//menu.add(R.string.search_anime).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
}
示例5: buildMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_skip, menu);
MenuItem next = menu.findItem(R.id.action_next);
MenuItemCompat.setShowAsAction(next,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getActivity().showWifiQr();
return true;
}
});
return true;
}
示例6: buildMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_search, menu);
SearchView searchView = new SearchView(getActivity());
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
MenuItemCompat.setActionView(searchMenuItem, searchView);
MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
searchView.setOnQueryTextListener(this);
return true;
}
示例7: buildMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.swap_next, menu);
MenuItem next = menu.findItem(R.id.action_next);
MenuItemCompat.setShowAsAction(next,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
getActivity().showSelectApps();
return true;
}
});
return true;
}
示例8: onCreateActionMode
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mAdapter.setMode(AnimeRecyclerAdapter.MODE_MULTI);
menu.add(R.string.favorite).setIcon(ThemeManager.getInstance(getActivity()).isLightBackground()
? R.drawable.ic_favorite_black_24dp : R.drawable.ic_favorite_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
return true;
}
示例9: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuItem shareMenuItem = menu.add(0, ID_MENU_SHARE, 0, R.string.menu_share).setIcon(R.drawable.ic_menu_share);
MenuItem saveMenuItem = menu.add(0, ID_MENU_SAVE, 0, R.string.menu_save).setIcon(android.R.drawable.ic_menu_save);
MenuItem bookmarkMenuItem = menu.add(0, ID_MENU_BOOKMARK, 0, R.string.menu_bookmark).setIcon(android.R.drawable.star_big_off);
MenuItemCompat.setShowAsAction(shareMenuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
MenuItemCompat.setShowAsAction(saveMenuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
MenuItemCompat.setShowAsAction(bookmarkMenuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
super.onCreateOptionsMenu(menu, inflater);
}
示例10: onPrepareOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public void onPrepareOptionsMenu(Menu menu) {
int mItemBaseID = 9600;
menu.clear();
menu.add(Menu.NONE, mItemBaseID, 1, R.string.sort)
.setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_sort_by_alpha_black_24dp : R.drawable.ic_sort_by_alpha_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, mItemBaseID + 1, 2, R.string.update)
.setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_refresh_black_24dp : R.drawable.ic_refresh_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, mItemBaseID + 2, 3, R.string.filter)
.setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_filter_list_black_24dp : R.drawable.ic_filter_list_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, mItemBaseID, 0, mDisplayType != Constants.DISPLAY_TYPE_LIST_LARGE ? "List" : "Grid").setIcon(mDisplayType != Constants.DISPLAY_TYPE_LIST_LARGE ? R.drawable.ic_view_list_white_24dp : R.drawable.ic_view_module_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(Menu.NONE, mItemBaseID, 0, "Columns").setIcon(R.drawable.ic_view_column_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
//menu.add(Menu.NONE, mItemBaseID + 3, 3, R.string.customize_tags);
//MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_NEVER);
//menu.add(Menu.NONE, mItemBaseID + 4, 4, R.string.import_favorites);
//MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_NEVER);
//menu.add(Menu.NONE, mItemBaseID + 5, 5, R.string.export_favorites);
//MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_NEVER);
//menu.add(Menu.NONE, mItemBaseID + 4, 5, R.string.filter).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
//menu.add(Menu.NONE, mItemBaseID + 13, 13, R.string.clear_all_favorites);
//MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_NEVER);
}
示例11: setItem
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
private void setItem(MenuItem item) {
item.setChecked(this.itemChecked).setVisible(this.itemVisible).setEnabled(this.itemEnabled).setCheckable(this.itemCheckable >= 1).setTitleCondensed(this.itemTitleCondensed).setIcon(this.itemIconResId).setAlphabeticShortcut(this.itemAlphabeticShortcut).setNumericShortcut(this.itemNumericShortcut);
if (this.itemShowAsAction >= 0) {
MenuItemCompat.setShowAsAction(item, this.itemShowAsAction);
}
if (this.itemListenerMethodName != null) {
if (SupportMenuInflater.this.mContext.isRestricted()) {
throw new IllegalStateException("The android:onClick attribute cannot be used within a restricted context");
}
item.setOnMenuItemClickListener(new InflatedOnMenuItemClickListener(SupportMenuInflater.this.getRealOwner(), this.itemListenerMethodName));
}
if (item instanceof MenuItemImpl) {
MenuItemImpl impl = (MenuItemImpl) item;
}
if (this.itemCheckable >= 2) {
if (item instanceof MenuItemImpl) {
((MenuItemImpl) item).setExclusiveCheckable(true);
} else if (item instanceof MenuItemWrapperICS) {
((MenuItemWrapperICS) item).setExclusiveCheckable(true);
}
}
boolean actionViewSpecified = false;
if (this.itemActionViewClassName != null) {
MenuItemCompat.setActionView(item, (View) newInstance(this.itemActionViewClassName, SupportMenuInflater.ACTION_VIEW_CONSTRUCTOR_SIGNATURE, SupportMenuInflater.this.mActionViewConstructorArguments));
actionViewSpecified = true;
}
if (this.itemActionViewLayout > 0) {
if (actionViewSpecified) {
Log.w(SupportMenuInflater.LOG_TAG, "Ignoring attribute 'itemActionViewLayout'. Action view already specified.");
} else {
MenuItemCompat.setActionView(item, this.itemActionViewLayout);
}
}
if (this.itemActionProvider != null) {
MenuItemCompat.setActionProvider(item, this.itemActionProvider);
}
}
示例12: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
/**
* Creates menu items such as "save" button
* @param menu the menu
* @return true
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuItem menuItem = menu.add(Menu.NONE, SAVE_BUTTON_ID, Menu.NONE, "Save");
MenuItemCompat.setShowAsAction(menuItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
return true;
}
示例13: onCreateActionMode
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add(R.string.select_mode).setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_select_all_black_24dp : R.drawable.ic_select_all_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(R.string.download)
.setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_file_download_black_24dp : R.drawable.ic_file_download_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(R.string.delete).setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_delete_black_24dp : R.drawable.ic_delete_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(R.string.mark_viewed);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
menu.add(R.string.mark_unviewed);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
return true;
}
示例14: onCreateActionMode
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mAdapter.setMode(MODE_MULTI);
menu.add(R.string.favorite).setIcon(ThemeManager.getInstance().isLightBackground() ? R.drawable.ic_favorite_border_black_24dp : R.drawable.ic_favorite_border_white_24dp);
MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
return true;
}
示例15: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
MenuItem menuItem = menu.add(MENU_GROUP, MENU_ITEM_REGISTER, 0, R.string.register);
MenuItemCompat.setShowAsAction(menuItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);
super.onCreateOptionsMenu(menu, inflater);
}