Java Code Examples for android.support.v4.view.MenuItemCompat#getActionView()

The following examples show how to use android.support.v4.view.MenuItemCompat#getActionView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From HideMockLocation with MIT License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.action_menu, menu);

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    // Resize searchView
    searchView.setMaxWidth(Integer.MAX_VALUE);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            adapter.filter(query);
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.filter(newText);
            return true;
        }
    });
    return true;
}
 
Example 2
Source File: MainActivity.java    From ListViewVariants with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menuItem_search));
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(final String query) {
            return false;
        }

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

    return super.onCreateOptionsMenu(menu);
}
 
Example 3
Source File: MyElectricMainFragment.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.me_menu, menu);
    super.onCreateOptionsMenu(menu, inflater);
    costSwitch = (SwitchCompat) MenuItemCompat.getActionView(menu.findItem(R.id.cost_switch));
    costSwitch.setOnCheckedChangeListener(checkedChangedListener);
    costSwitch.setChecked(blnShowCost);
}
 
Example 4
Source File: WebActivity.java    From Android_framework with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (isUseToolbar()){
        getMenuInflater().inflate(R.menu.menu_webactivity_refresh, menu);
        MenuItem item = menu.findItem(R.id.menu_refresh);
        View view = MenuItemCompat.getActionView(item);
        ((ViewGroup) view).addView(refresh);
        return true;
    }
    else
        return super.onCreateOptionsMenu(menu);
}
 
Example 5
Source File: TriggersFragment.java    From hawkular-android-client with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    super.onCreateOptionsMenu(menu, menuInflater);
    menuInflater.inflate(R.menu.menu_search, menu);

    MenuItem item = menu.findItem(R.id.menu_search1);
    searchView = (SearchView) MenuItemCompat.getActionView(item);
    searchView.setOnQueryTextListener(this);
    if (searchText != null) {
        searchView.setQuery(searchText, false);
    }
}
 
Example 6
Source File: ActivityMain.java    From Android-Firewall with GNU General Public License v3.0 5 votes vote down vote up
@Override+
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

    // Search
    searchItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (adapter != null)
                adapter.getFilter().filter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (adapter != null)
                adapter.getFilter().filter(newText);
            return true;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (adapter != null)
                adapter.getFilter().filter(null);
            return true;
        }
    });

    return true;
}
 
Example 7
Source File: RecipeItemListActivity.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
private void setUpSearchView(Menu menu) {
	MenuItem menuItem = menu.findItem(R.id.action_search);
	searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
	searchView.setIconifiedByDefault(false);
	SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
	searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
	MenuItemCompat.setOnActionExpandListener(menuItem, this);
	searchView.setOnSuggestionListener(this);

}
 
Example 8
Source File: ProductsFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.product_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.product_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 9
Source File: BaseActivity.java    From open with GNU General Public License v3.0 5 votes vote down vote up
private void restoreCurrentSearchTerm() {
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    if (app.getCurrentSearchTerm() != null) {
        searchMenuItem.expandActionView();
        searchView.setQuery(app.getCurrentSearchTerm(), false);
    }
}
 
Example 10
Source File: HomeActivity.java    From Pasta-Music with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);

    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            search(query, false);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (preload) search(newText, true);
            return true;
        }
    });

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (f instanceof SearchFragment) onBackPressed();
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example 11
Source File: HomeActivity.java    From Movie-Check with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.home, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return super.onCreateOptionsMenu(menu);
}
 
Example 12
Source File: PasswordViewFragment.java    From masterpassword with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.password_view, menu);

    searchItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
}
 
Example 13
Source File: MainActivity.java    From Searchable-RecyclerView-Demo with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);

    return true;
}
 
Example 14
Source File: OrdersFragment.java    From Woodmin with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //menu.clear();
    super.onCreateOptionsMenu(menu,inflater);
    inflater.inflate(R.menu.order_fragment_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    if (searchView != null) {
        List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch();
        SearchableInfo info = searchManager.getSearchableInfo(getActivity().getComponentName());
        for (SearchableInfo inf : searchables) {
            if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) {
                info = inf;
            }
        }
        searchView.setSearchableInfo(info);
        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint(getActivity().getString(R.string.order_title_search));

        if(mQuery != null && mQuery.length() > 0) {
            searchView.setQuery(mQuery, true);
            searchView.setIconifiedByDefault(false);
            searchView.performClick();
            searchView.requestFocus();
        } else {
            searchView.setIconifiedByDefault(true);
        }
    }

}
 
Example 15
Source File: MusicFragment.java    From TouchNews with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_music, menu);
    super.onCreateOptionsMenu(menu, inflater);
    mMenuItemSearch = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    mMenuItemSearch.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            mListView.setVisibility(View.GONE);
            //刷新待选List 为默认值
            updateSearchList(mSearchChooseDef);
            return false;
        }
    });
    //文本输入框可见、显示ListView
    mMenuItemSearch.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                mListView.setVisibility(View.VISIBLE);
            }
        }
    });
    mMenuItemSearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //文本输入改变实时搜索关键字
            mMusicsPresenter.searchMusic(newText);
            //文本输入改变 List 滑动到顶部
            mListView.setSelection(0);
            return true;
        }
    });

}
 
Example 16
Source File: ReadCHMActivity.java    From fangzhuishushenqi with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_chm_reader, menu);

    MenuItem searchMenuItem = menu.findItem(R.id.menu_search);//在菜单中找到对应控件的item
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            mWebView.clearMatches();
            return false;
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mWebView.findAllAsync(newText);
            try {
                for (Method m : WebView.class.getDeclaredMethods()) {
                    if (m.getName().equals("setFindIsUp")) {
                        m.setAccessible(true);
                        m.invoke(mWebView, true);
                        break;
                    }
                }
            } catch (Exception ignored) {
            }
            return false;
        }
    });
    return true;
}
 
Example 17
Source File: CityActivity.java    From easyweather with MIT License 5 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_city_list,menu);
        SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
        final MenuItem searchItem = menu.findItem(R.id.search);
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        if(searchView == null) return false;
//        searchView.setIconified(false);
        searchView.setQueryHint("搜索城市,暂不支持拼音");
        searchView.setSearchableInfo( searchManager.getSearchableInfo(CityActivity.this.getComponentName()) );
        AutoCompleteTextView textView = (AutoCompleteTextView)searchView.findViewById(R.id.search_src_text);
        if (textView != null){
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        }

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
                }
                searchView.clearFocus();

                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
        return true;
    }
 
Example 18
Source File: FoldingLayoutActivity.java    From Folding-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	if (IS_JBMR2) {
		getMenuInflater().inflate(R.menu.fold_with_bug, menu);
	} else {
		getMenuInflater().inflate(R.menu.fold, menu);
	}
	MenuItem spinerItem = menu.findItem(R.id.num_of_folds);
	Spinner s = (Spinner) MenuItemCompat.getActionView(spinerItem);

	s.setOnItemSelectedListener(mItemSelectedListener);

	return true;
}
 
Example 19
Source File: OCFileListFragment.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    searchItem = menu.findItem(R.id.action_search);
    layoutView = menu.findItem(R.id.action_changeView);

    // create search bar and search listener
    if (searchItem != null) {
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(this);
    }
}
 
Example 20
Source File: TeamFragment.java    From droidddle with Apache License 2.0 4 votes vote down vote up
private void startMenuLoading() {
    MenuItemCompat.setActionView(mFollowMenu, R.layout.menu_item_action_refresh);
    MenuItemCompat.expandActionView(mFollowMenu);
    View view = MenuItemCompat.getActionView(mFollowMenu);
    ((ProgressView) view.findViewById(R.id.progress)).start();
}