Java Code Examples for android.view.MenuItem.getActionView()

The following are Jave code examples for showing how to use getActionView() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: q-mail   File: ChooseFolder.java   View Source Code Vote up 6 votes
private void configureFolderSearchView(Menu menu) {
    final MenuItem folderMenuItem = menu.findItem(R.id.filter_folders);
    final SearchView folderSearchView = (SearchView) folderMenuItem.getActionView();
    folderSearchView.setQueryHint(getString(R.string.folder_list_filter_hint));
    folderSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            folderMenuItem.collapseActionView();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mAdapter.getFilter().filter(newText);
            return true;
        }
    });
}
 
Example 2
Project: LaunchEnr   File: IconChooser.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.search_menu, menu);

    MenuItem search = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) search.getActionView();
    initQueryTextListener(searchView);

    return true;
}
 
Example 3
Project: NeoTerm   File: TabSwitcher.java   View Source Code Vote up 6 votes
/**
 * Setups the tab switcher to be associated with those menu items of a specific menu, which use
 * a {@link TabSwitcherButton} as their action view. The icon of such menu items will
 * automatically be updated, when the number of tabs, which are contained by the tab switcher,
 * changes.
 *
 * @param tabSwitcher
 *         The tab switcher, which should become associated with the menu items, as an instance
 *         of the class {@link TabSwitcher}. The tab switcher may not be null
 * @param menu
 *         The menu, whose menu items should become associated with the given tab switcher, as
 *         an instance of the type {@link Menu}. The menu may not be null
 * @param listener
 *         The listener, which should be set to the menu items, which use a {@link
 *         TabSwitcherButton} as their action view, as an instance of the type {@link
 *         OnClickListener} or null, if no listener should be set
 */
public static void setupWithMenu(@NonNull final TabSwitcher tabSwitcher,
                                 @NonNull final Menu menu,
                                 @Nullable final OnClickListener listener) {
    ensureNotNull(tabSwitcher, "The tab switcher may not be null");
    ensureNotNull(menu, "The menu may not be null");

    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        View view = menuItem.getActionView();

        if (view instanceof TabSwitcherButton) {
            TabSwitcherButton tabSwitcherButton = (TabSwitcherButton) view;
            tabSwitcherButton.setOnClickListener(listener);
            tabSwitcherButton.setCount(tabSwitcher.getCount());
            tabSwitcher.addListener(tabSwitcherButton);
        }
    }
}
 
Example 4
Project: InifiniteRecyclerView   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);

    SearchManager searchManager = (SearchManager)
            getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();

    searchView.setSearchableInfo(searchManager.
            getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(this);
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, this);

    return true;
}
 
Example 5
Project: TheNounProject   File: BaseSearchFragment.java   View Source Code Vote up 6 votes
private void setupSearchView(MenuItem searchItem) {
    if (searchItem != null) {
        MenuItemCompat.setOnActionExpandListener(searchItem, this);
        SearchManager searchManager = (SearchManager) (getActivity()
                .getSystemService(Context.SEARCH_SERVICE));
        searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            searchView.setSearchableInfo(searchManager
                    .getSearchableInfo(getActivity().getComponentName()));
            searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
            searchView.clearFocus();
            searchView.setOnQueryTextListener(this);
            setupSearchOptions(searchView);
        }
    }
}
 
Example 6
Project: IslamicLibraryAndroid   File: BookCategoryFragment.java   View Source Code Vote up 6 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.fragment_category, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) item.getActionView();
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mBookCategoryRecyclerViewAdapter.getFilter().filter(newText);
            return true;
        }
    });
}
 
Example 7
Project: ss-android   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_activity_actions, menu);

    MenuItem menuItem = menu.findItem(R.id.menu_item_switch);
    if (menuItem == null) {
        return false;
    }

    switchProxy = (Switch) menuItem.getActionView();
    if (switchProxy == null) {
        return false;
    }

    switchProxy.setChecked(LocalVpnService.IsRunning);
    switchProxy.setOnCheckedChangeListener(this);

    return true;
}
 
Example 8
Project: MusicX-music-player   File: ToolbarProcessor.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, final @ColorInt int color) {
    try {
        final Field field = Toolbar.class.getDeclaredField("mCollapseIcon");
        field.setAccessible(true);
        Drawable collapseIcon = (Drawable) field.get(toolbar);
        if (collapseIcon != null) {
            field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // credits: https://snow.dog/blog/how-to-dynamicaly-change-android-toolbar-icons-color/
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        final View v = toolbar.getChildAt(i);
        // We can't iterate through the toolbar.getMenu() here, because we need the ActionMenuItemView. ATEActionMenuItemView is overriding the item icon tint color.
        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView) innerView).getCompoundDrawables().length;
                    for (int k = 0; k < drawablesCount; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            ((ActionMenuItemView) innerView).getCompoundDrawables()[k].setColorFilter(colorFilter);
                        }
                    }
                }
            }
        }
    }

    if (menu == null)
        menu = toolbar.getMenu();
    if (menu != null && menu.size() > 0) {
        for (int i = 0; i < menu.size(); i++) {
            final MenuItem item = menu.getItem(i);
            // We must iterate through the toolbar.getMenu() too, to keep the tint when resuming the paused activity.
            if (item.getIcon() != null) {
                item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color));
            }
            // Search view theming
            if (item.getActionView() != null && (item.getActionView() instanceof android.widget.SearchView || item.getActionView() instanceof android.support.v7.widget.SearchView)) {
                SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color);
            }
        }
    }
}
 
Example 9
Project: 2017.1-Trezentos   File: SearchActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.search_navigation, menu);
    MenuItem searchViewItem = menu.findItem(R.id.action_search);

    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) searchViewItem.getActionView();
    searchView.setQueryHint("Search");
    searchView.setSearchableInfo(searchManager
            .getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);// Do not iconify the widget; expand it by defaul

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // Adapter that will be filtered
            classAdapter.getFilter().filter(newText);
            return true;
        }

        public boolean onQueryTextSubmit(String query) {

            return true;
        }
    };

    searchView.setOnQueryTextListener(queryTextListener);
    return true;
}
 
Example 10
Project: dagger-test-example   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    this.searchViewObservable(searchView)
        .distinctUntilChanged()
        .debounce(1000, TimeUnit.MILLISECONDS)
        .observeOn(androidScheduler)
        .doOnNext(disposable -> mViewPager.setCurrentItem(SectionsPagerAdapter.POSITION_SEARCH, true))
        .doOnNext(s -> searchView.clearFocus())
        .subscribeWith(searchSubject);
    return true;
}
 
Example 11
Project: ecam-app-android   File: FoodSearchActivity.java   View Source Code Vote up 5 votes
@Override
//Using search widget
public boolean onCreateOptionsMenu(Menu menu){

    // Search in the toolbar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    inflater.inflate(R.menu.search_menu,menu);
    MenuItem item=menu.findItem(R.id.action_search);
    SearchView searchView=(SearchView) item.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){

        @Override
        public boolean onQueryTextSubmit(String query){
            destinationClass = FoodSearchActivity.class;
            Intent intent = new Intent(context, destinationClass);
            // Pass info to the FoodSearchActivity
            intent.putExtra("SEARCH_TERM", query.toString());

            startActivity(intent);
            return false;
        }
        public boolean onQueryTextChange(String newText){

            return false;
        }
    });
    return true;
}
 
Example 12
Project: ecam-app-android   File: FoodFavoriteActivity.java   View Source Code Vote up 5 votes
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    inflater.inflate(R.menu.search_menu,menu);
    inflater.inflate(R.menu.refresh_menu,menu);
    MenuItem item=menu.findItem(R.id.action_search);
    SearchView searchView=(SearchView) item.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){

        @Override
        public boolean onQueryTextSubmit(String query){
            destinationClass = FoodSearchActivity.class;
            Intent intent = new Intent(context, destinationClass);

            // Pass info to the FoodSearchActivity
            intent.putExtra("SEARCH_TERM", query.toString());

            startActivity(intent);
            return false;
        }
        public boolean onQueryTextChange(String newText){

            return false;
        }
    });
    return true;
}
 
Example 13
Project: UpdogFarmer   File: GamesFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_games, menu);
    final MenuItem searchItem = menu.findItem(R.id.search);
    searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(this);
    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 14
Project: PopCorn   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    final MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setQueryHint(getResources().getString(R.string.search_movies_tv_shows_people));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!NetworkConnection.isConnected(MainActivity.this)) {
                Toast.makeText(MainActivity.this, R.string.no_network, Toast.LENGTH_SHORT).show();
                return true;
            }
            Intent intent = new Intent(MainActivity.this, SearchActivity.class);
            intent.putExtra(Constant.QUERY, query);
            startActivity(intent);
            searchMenuItem.collapseActionView();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    return true;
}
 
Example 15
Project: Treebolic   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(@NonNull final Menu menu)
{
	// inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.main, menu);

	// search view
	final MenuItem searchMenuItem = menu.findItem(R.id.action_search);
	final SearchView searchView = (SearchView) searchMenuItem.getActionView();
	searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
	{
		@Override
		public boolean onQueryTextSubmit(final String query)
		{
			searchView.clearFocus();
			searchView.setQuery("", false);
			tryStartTreebolic(query);
			return true;
		}

		@Override
		public boolean onQueryTextChange(final String newText)
		{
			return false;
		}
	});

	return true;
}
 
Example 16
Project: StopApp   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) searchMenuItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setIconifiedByDefault(false);
    ImageView search_mag_icon = (ImageView) searchView.findViewById(R.id.search_mag_icon);
    search_mag_icon.setImageResource(0);
    LinearLayout search_plate = (LinearLayout) searchView.findViewById(R.id.search_plate);
    search_plate.setBackgroundColor(Color.TRANSPARENT);
    searchView.setOnQueryTextListener(mQueryListener);
    return true;
}
 
Example 17
Project: Pocket-Plays-for-Twitch   File: IntroductoryOverlay.java   View Source Code Vote up 4 votes
/**
 * Set the {@link MenuItem} referencing the cast button.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public Builder setMenuItem(MenuItem menuItem) {
    mView = menuItem.getActionView();
    return this;
}
 
Example 18
Project: LaravelNewsApp   File: MenuTint.java   View Source Code Vote up 4 votes
/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>
 * <p>
 * <p>Call this method after inflating/creating your menu in
 * {@link Activity#onCreateOptionsMenu(Menu)}.</p>
 * <p>
 * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p>
 *
 * @param activity the activity to apply the menu tinting on.
 */
public void apply(final Activity activity) {

    if (forceIcons) {
        forceMenuIcons(menu);
    }

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        colorMenuItem(item, menuItemIconColor, menuItemIconAlpha);
        if (reApplyOnChange) {
            View view = item.getActionView();
            if (view != null) {
                if (item instanceof MenuItemImpl) {
                    ((MenuItemImpl) item).setSupportOnActionExpandListener(
                            new SupportActionExpandListener(this));
                } else {
                    item.setOnActionExpandListener(new NativeActionExpandListener(this));
                }
            }
        }
    }

    actionBarView = findActionBar(activity);
    if (actionBarView == null) {
        Log.w(TAG, "Could not find the ActionBar");
        return;
    }

    // We must wait for the view to be created to set a color filter on the drawables.
    actionBarView.post(new Runnable() {

        @Override
        public void run() {
            for (int i = 0, size = menu.size(); i < size; i++) {
                MenuItem menuItem = menu.getItem(i);
                if (isInOverflow(menuItem)) {
                    colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha);
                }
                if (menuItem.hasSubMenu()) {
                    SubMenu subMenu = menuItem.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha);
                    }
                }
            }
            if (menuItemIconColor != null || menuItemIconAlpha != null) {
                overflowButton = findOverflowMenuButton(activity, actionBarView);
                colorOverflowMenuItem(overflowButton);
            }
        }
    });
}
 
Example 19
Project: boohee_v5.6   File: MenuItemCompatHoneycomb.java   View Source Code Vote up 4 votes
public static View getActionView(MenuItem item) {
    return item.getActionView();
}
 
Example 20
Project: android_ui   File: ActionTextButton.java   View Source Code Vote up 3 votes
/**
 * Obtains action view of an item with the specified <var>itemId</var> from the given <var>menu</var>.
 *
 * @param menu   The menu where is the item presented.
 * @param itemId Id of the menu item of which action view to obtain.
 * @return Obtained view or {@code null} if the item does not have action view or it is not
 * presented within the given menu.
 */
@SuppressLint("NewApi")
private static View obtainActionView(Menu menu, int itemId) {
	final MenuItem menuItem = menu.findItem(itemId);
	if (menuItem == null) return null;
	return COMPAT_MODE ? MenuItemCompat.getActionView(menuItem) : menuItem.getActionView();
}