當前位置: 首頁>>代碼示例>>Java>>正文


Java MenuItemCompat.setShowAsAction方法代碼示例

本文整理匯總了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;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:17,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:20,代碼來源:OfflineHistoryMaterialFragment.java

示例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;
}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:21,代碼來源:ViewHabitActivity.java

示例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);
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:24,代碼來源:LibraryFragment.java

示例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;
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:16,代碼來源:NfcView.java

示例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;
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:15,代碼來源:SwapAppsView.java

示例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;
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:16,代碼來源:JoinWifiView.java

示例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;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:9,代碼來源:AnimeCardGridFragment.java

示例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);
}
 
開發者ID:CactusSoft,項目名稱:zabbkit-android,代碼行數:11,代碼來源:GraphFragment.java

示例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);
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:28,代碼來源:FavoritesFragment.java

示例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);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:38,代碼來源:SupportMenuInflater.java

示例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;
}
 
開發者ID:CMPUT301F17T13,項目名稱:cat-is-a-dog,代碼行數:13,代碼來源:AddHabitEventActivity.java

示例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;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:16,代碼來源:AnimeMaterialListFragment.java

示例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;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:8,代碼來源:HistoryMaterialFragment.java

示例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);
}
 
開發者ID:benniaobuguai,項目名稱:android-project-gallery,代碼行數:9,代碼來源:UserLoginFragment.java


注:本文中的android.support.v4.view.MenuItemCompat.setShowAsAction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。