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


Java MenuItemCompat.setActionView方法代碼示例

本文整理匯總了Java中android.support.v4.view.MenuItemCompat.setActionView方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuItemCompat.setActionView方法的具體用法?Java MenuItemCompat.setActionView怎麽用?Java MenuItemCompat.setActionView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.view.MenuItemCompat的用法示例。


在下文中一共展示了MenuItemCompat.setActionView方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildMenu

import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {

    inflater.inflate(R.menu.swap_next_search, menu);
    MenuItem nextMenuItem = menu.findItem(R.id.action_next);
    int flags = MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
    MenuItemCompat.setShowAsAction(nextMenuItem, flags);
    nextMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            getActivity().onAppsSelected();
            return true;
        }
    });

    SearchView searchView = new SearchView(getActivity());

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    MenuItemCompat.setActionView(searchMenuItem, searchView);
    MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    searchView.setOnQueryTextListener(this);
    return true;
}
 
開發者ID:uhuru-mobile,項目名稱:mobile-store,代碼行數:25,代碼來源:SelectAppsView.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: 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

示例4: 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

示例5: 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

示例6: onPrepareOptionsMenu

import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    // Place an action bar item for searching.
    if (MAVApplication.getInstance().getRepository().isFavorite(mAnimeUrl))
        menu.add(Menu.NONE, mItemBaseID, 0, R.string.favorite).setIcon(ThemeManager.getInstance(getActivity()).isLightBackground()
                ? R.drawable.ic_favorite_black_24dp : R.drawable.ic_favorite_white_24dp);
    else
        menu.add(Menu.NONE, mItemBaseID, 0, R.string.favorite).setIcon(ThemeManager.getInstance(getActivity()).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);
    menu.add(Menu.NONE, mItemBaseID + 1, 0, 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);
    MenuItem item = menu.add(Menu.NONE, mItemBaseID + 2, 0, R.string.search_episodes);
    item.setIcon(ThemeManager.getInstance(getActivity()).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 EpisodeSearchView(getActivity());
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setOnCloseListener(this);
    mSearchView.setIconifiedByDefault(true);
    MenuItemCompat.setActionView(item, mSearchView);
    menu.add(Menu.NONE, mItemBaseID + 3, 0, R.string.sort_episodes).setIcon(android.R.drawable.ic_menu_sort_alphabetically);
    MenuItemCompat.setShowAsAction(menu.getItem(menu.size() - 1), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    menu.add(Menu.NONE, mItemBaseID + 4, 0, R.string.download).setIcon(ThemeManager.getInstance(getActivity()).isLightBackground() ? R.drawable.ic_file_download_black_24dp : R.drawable.ic_file_download_white_24dp);
    menu.add(Menu.NONE, mItemBaseID + 5, 0, R.string.mark_viewed);
    menu.add(Menu.NONE, mItemBaseID + 6, 0, R.string.mark_unviewed);
    //menu.add(Menu.NONE, mItemBaseID + 9, 0, "Show/Hide Viewed Episodes");
    //menu.add(Menu.NONE, mItemBaseID + 10, 0, R.string.share);
    //menu.add(Menu.NONE, mItemBaseID + 11, 0, "Find Alternate Sources");
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:33,代碼來源:AnimeMaterialListFragment.java

示例7: 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

示例8: onCreateActionMode

import android.support.v4.view.MenuItemCompat; //導入方法依賴的package包/類
@Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {


//            mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search_menu));
            mSearchView = new SearchView(getSupportActionBar().getThemedContext());
            ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
            mSearchView.setLayoutParams(params);
            mSearchView.setLayoutParams(new ActionBar.LayoutParams(Gravity.LEFT));
            mSearchView.setMaxWidth(Integer.MAX_VALUE);


//            mSearchView = new SearchView();


            setupSearchView(mSearchView);

            // search menu item
            MenuItem searchMenuItem = menu.add(Menu.NONE, Menu.NONE, 2, getString(R.string.menu_search));
            searchMenuItem.setIcon(R.drawable.search);
            searchMenuItem.expandActionView();
            MenuItemCompat.setActionView(searchMenuItem, mSearchView);
            MenuItemCompat.setShowAsAction(searchMenuItem, MenuItem.SHOW_AS_ACTION_ALWAYS);


            MenuItem searchMenuItem3 = menu.add(Menu.NONE, Menu.NONE, 1, getString(R.string.menu_search));
            searchMenuItem3.setIcon(R.drawable.search);
            MenuItemCompat.setActionView(searchMenuItem3, iv);
            MenuItemCompat.setShowAsAction(searchMenuItem3, MenuItem.SHOW_AS_ACTION_ALWAYS);


            return true;
        }
 
開發者ID:Elbehiry,項目名稱:Viajes,代碼行數:34,代碼來源:MainActivity.java


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