android.view.Menu.findItem()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中android.view.Menu.findItem()方法的一些代码示例,展示了Menu.findItem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu.findItem()方法的具体详情如下:
包路径:android.view.Menu
类名称:Menu
方法名:findItem

暂无

代码示例

代码示例来源:origin: stackoverflow.com

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.my_menu, menu);

  final MenuItem item = menu.findItem(R.id.menu_foo);
  item.getActionView().setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      onOptionsItemSelected(item);
    }
  });

  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: stackoverflow.com

import android.support.v7.widget.SearchView;

...

public class YourActivity extends AppCompatActivity {

  ...

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);
    // Retrieve the SearchView and plug it into SearchManager
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return true;
  }

  ... 

}

代码示例来源:origin: stackoverflow.com

public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater menuInflater = getMenuInflater();
  menuInflater.inflate(R.menu.dashboard, menu);

   MenuItem searchItem = menu.findItem(R.id.action_search);

  SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE);

  SearchView searchView = null;
  if (searchItem != null) {
    searchView = (SearchView) searchItem.getActionView();
  }
  if (searchView != null) {
    searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
  }
    return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: stackoverflow.com

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater inflater = getMenuInflater();
 inflater.inflate(R.menu.menu, menu);

 MenuItem searchItem = menu.findItem(R.id.action_search);
 SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
 if (searchView != null) {
   searchView.setOnQueryTextListener(this);
 }

 return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: stackoverflow.com

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.main_menu, menu);
   final Menu m = menu;
   final MenuItem item = menu.findItem(R.id.ActionConnection);
   item.getActionView().setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {   
       sync();
     }
   });
   return true;
 }

代码示例来源:origin: stackoverflow.com

inflater.inflate(R.menu.country_list_activity_actions, menu);
mSearchMenu = menu.findItem(R.id.action_search);
  mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  mSearchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
 inflater.inflate(R.menu.actions, menu);
 server=menu.findItem(R.id.server);
 discover=menu.findItem(R.id.discover);
 allowDiscovery=menu.findItem(R.id.allow_disco);
 updateMenu();
 super.onCreateOptionsMenu(menu, inflater);
}

代码示例来源:origin: stackoverflow.com

@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);
  SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
  // Tells your app's SearchView to use this activity's searchable configuration
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

  return true;
}

代码示例来源:origin: stackoverflow.com

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.actionbarhelpmenu, menu);
   final Menu m = menu;
   final MenuItem item = menu.findItem(R.id.ActionConnection);
   item.getActionView().setOnClickListener(new OnClickListener() {
     @Override
     public void onClick(View v) {   
       m.performIdentifierAction(item.getItemId(), 0);
     }
   });
   return true;
 }

代码示例来源:origin: pockethub/PocketHub

@Override
public boolean onCreateOptionsMenu(Menu options) {
  getMenuInflater().inflate(R.menu.activity_search, options);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchItem = options.findItem(R.id.m_search);
  searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  Bundle args = new Bundle();
  args.putParcelable(EXTRA_REPOSITORY, repository);
  searchView.setAppSearchData(args);
  return true;
}

代码示例来源:origin: stackoverflow.com

public class Activity extends android.app.Activity
{
  @Override
  public boolean onCreateOptionsMenu( Menu menu )
  {
    getMenuInflater().inflate( R.menu.main, menu );

    // Add SearchWidget.
    SearchManager searchManager = (SearchManager) getSystemService( Context.SEARCH_SERVICE );
    SearchView searchView = (SearchView) menu.findItem( R.id.options_menu_main_search ).getActionView();

    searchView.setSearchableInfo( searchManager.getSearchableInfo( getComponentName() ) );

    return super.onCreateOptionsMenu( menu );
  }
}

代码示例来源:origin: stackoverflow.com

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  MenuItem searchViewMenuItem = menu.findItem(R.id.action_search);    
  mSearchView = (SearchView) searchViewMenuItem.getActionView();
  int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
  ImageView v = (ImageView) mSearchView.findViewById(searchImgId);
  v.setImageResource(R.drawable.your_new_icon); 
  mSearchView.setOnQueryTextListener(this);
  return super.onPrepareOptionsMenu(menu);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 getMenuInflater().inflate(R.menu.actions, menu);
 play=menu.findItem(R.id.play);
 pause=menu.findItem(R.id.pause);
 stop=menu.findItem(R.id.stop);
 return(super.onCreateOptionsMenu(menu));
}

代码示例来源:origin: stackoverflow.com

public boolean onCreateOptionsMenu(Menu menu) {
   super.onCreateOptionsMenu(menu);
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.action_bar, menu);
   MenuItem searchItem = menu.findItem(R.id.menu_item_search);
   SearchView searchView = (SearchView) searchItem.getActionView();
   SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
   if(null!=searchManager ) {   
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
   }
   searchView.setIconifiedByDefault(false);
   return true;
 }

代码示例来源:origin: bumptech/glide

@Override
public boolean onCreateOptionsMenu(Menu menu) {
 MenuInflater menuInflater = getMenuInflater();
 menuInflater.inflate(R.menu.search_activity, menu);
 searchView = (SearchView) menu.findItem(R.id.search).getActionView();
 searchView.setSubmitButtonEnabled(true);
 searchView.setIconified(false);
 searchView.setOnQueryTextListener(this);
 return true;
}

代码示例来源:origin: pockethub/PocketHub

@Override
public boolean onCreateOptionsMenu(Menu options) {
  getMenuInflater().inflate(R.menu.activity_search, options);
  SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  MenuItem searchItem = options.findItem(R.id.m_search);
  searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
  searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
  return true;
}

代码示例来源:origin: stackoverflow.com

public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.menu_contacts, menu);

  SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView();
  search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));

  AutoCompleteTextView searchTextView = (AutoCompleteTextView) search.findViewById(android.support.v7.appcompat.R.id.search_src_text);
  try {
    Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
    mCursorDrawableRes.setAccessible(true);
    mCursorDrawableRes.set(searchTextView, R.drawable.cursor); //This sets the cursor resource ID to 0 or @null which will make it visible on white background
  } catch (Exception e) {
  }
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: stackoverflow.com

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.actionbar_main, menu);
  final ActionBar actionBar = getActionBar();
  final MenuItem customizerItem = menu.findItem(R.id.MenuItemCustomize);
  View v = customizerItem.getActionView();
  customizerActionView = (ImageButton) v;
  customizerActionView.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
      onOptionsItemSelected(customizerItem);
    }
  });
}

代码示例来源:origin: stackoverflow.com

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.badge, menu);

  RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.badge).getActionView();
  TextView tv = (TextView) badgeLayout.findViewById(R.id.actionbar_notifcation_textview);
  tv.setText("12");
}

代码示例来源:origin: stackoverflow.com

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  inflater.inflate(R.menu.menu, menu);
  MenuItem searchItem = menu.findItem(R.id.action_search);
  SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) searchItem.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

相关文章