当前位置: 首页>>代码示例>>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;未经允许,请勿转载。