本文整理匯總了Java中android.view.MenuItem.getActionView方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuItem.getActionView方法的具體用法?Java MenuItem.getActionView怎麽用?Java MenuItem.getActionView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.getActionView方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configureFolderSearchView
import android.view.MenuItem; //導入方法依賴的package包/類
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;
}
});
}
示例2: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例3: setupWithMenu
import android.view.MenuItem; //導入方法依賴的package包/類
/**
* 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);
}
}
}
示例4: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例5: setupSearchView
import android.view.MenuItem; //導入方法依賴的package包/類
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);
}
}
}
示例6: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
});
}
示例7: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例8: tintMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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);
}
}
}
}
示例9: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例10: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例11: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例12: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
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;
}
示例13: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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);
}
示例14: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}
示例15: onCreateOptionsMenu
import android.view.MenuItem; //導入方法依賴的package包/類
@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;
}