本文整理了Java中android.view.MenuItem.setOnActionExpandListener()
方法的一些代码示例,展示了MenuItem.setOnActionExpandListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MenuItem.setOnActionExpandListener()
方法的具体详情如下:
包路径:android.view.MenuItem
类名称:MenuItem
方法名:setOnActionExpandListener
暂无
代码示例来源:origin: stackoverflow.com
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu, menu);
final EditText editText = (EditText) menu.findItem(
R.id.menu_search).getActionView();
editText.addTextChangedListener(textWatcher);
MenuItem menuItem = menu.findItem(R.id.menu_search);
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
editText.clearFocus();
return true; // Return true to expand action view
}
});
}
代码示例来源:origin: stackoverflow.com
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH)
menuItem.setOnActionExpandListener(new OnActionExpandListener()
代码示例来源:origin: robolectric/robolectric
@Test
public void setOnActionExpandListener_shouldReturnMenuItem() throws Exception {
assertThat(item.setOnActionExpandListener(listener)).isSameAs(item);
}
代码示例来源:origin: commonsguy/cw-omnibus
private void configureSearchView(Menu menu) {
MenuItem search=menu.findItem(R.id.search);
search.setOnActionExpandListener(this);
sv=(SearchView)search.getActionView();
sv.setOnQueryTextListener(this);
sv.setSubmitButtonEnabled(true);
sv.setIconifiedByDefault(true);
if (initialQuery != null) {
sv.setIconified(false);
search.expandActionView();
sv.setQuery(initialQuery, true);
}
}
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() throws Exception {
item = new RoboMenuItem(ApplicationProvider.getApplicationContext());
listener = new TestOnActionExpandListener();
item.setOnActionExpandListener(listener);
}
代码示例来源:origin: ankidroid/Anki-Android
mMySearchesItem.setVisible(savedFiltersObj != null && savedFiltersObj.length() > 0);
mSearchItem = menu.findItem(R.id.action_search);
mSearchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
代码示例来源:origin: robolectric/robolectric
item = item.setNumericShortcut('6');
assertThat(item).isNotNull();
item = item.setOnActionExpandListener(null);
assertThat(item).isNotNull();
item = item.setShortcut('6', 'z');
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options, menu);
MenuItem menuItem = menu.findItem(R.id.actionItem);
...
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
return true; // Return true to expand action view
}
});
}
代码示例来源:origin: stackoverflow.com
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activitymenu, menu);
MenuItem menuItem=menu.findItem(R.id.menuSearch);
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
mAbSearch=(AutoCompleteTextView) item.getActionView().findViewById(R.id.ab_Search);
// Set your adapter and do whatever you want
return true;
}
});
代码示例来源:origin: ukanth/afwall
private void search(MenuItem item) {
item.setActionView(R.layout.searchbar);
final EditText filterText = (EditText) item.getActionView().findViewById(
R.id.searchApps);
filterText.addTextChangedListener(filterTextWatcher);
filterText.setEllipsize(TruncateAt.END);
filterText.setSingleLine();
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
selectFilterGroup();
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
filterText.post(() -> {
filterText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(filterText, InputMethodManager.SHOW_IMPLICIT);
});
return true; // Return true to expand action view
}
});
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity, menu);
MenuItem searchMI = (MenuItem) menu.findItem(R.id.menu_search);
searchMI.setOnActionExpandListener(new OnActionExpandListener(){
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
//nothing
return true;
}
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
getActionBar().setDisplayShowHomeEnabled(false);
return true;
}
});
return true;
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options, menu);
MenuItem menuItem = menu.findItem(R.id.actionItem);
...
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
return true; // Return true to expand action view
}
});
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options, menu);
MenuItem menuItem = menu.findItem(R.id.actionItem);
...
menuItem.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
return true; // Return true to expand action view
}
});
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_activity, menu);
MenuItem searchMI = (MenuItem) menu.findItem(R.id.menu_search);
searchMI.setOnActionExpandListener(new OnActionExpandListener(){
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
// Hide menu icon
return true;
}
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
// Show menu icon
return true;
}
});
return true;
}
代码示例来源:origin: kingargyle/adt-leanback-support
public static MenuItem setOnActionExpandListener(MenuItem item,
SupportActionExpandProxy listener) {
return item.setOnActionExpandListener(new OnActionExpandListenerWrapper(listener));
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_menu, menu);
MenuItem menu_search = menu.findItem(actionbar_search);
menu_search.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
//get focus
item.getActionView().requestFocus();
//get input method
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
return true; // Return true to expand action view
}
});
return true;
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
MenuItem menu_search = menu.findItem(R.id.menu_search);
menu_search.setOnActionExpandListener(new OnActionExpandListener() {
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when collapsed
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
//get focus
item.getActionView().requestFocus();
//get input method
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
return true; // Return true to expand action view
}
});
return true;
}
代码示例来源:origin: stackoverflow.com
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
SearchView searchView = new SearchView(((SherlockFragmentActivity) getActivity()).getSupportActionBar().getThemedContext());
searchView.setIconifiedByDefault(true);
// ...
MenuItem menuItem = menu.add(R.string.search);
// ...
menuItem.setOnActionExpandListener(this);
}
@Override
public boolean onMenuItemActionExpand(final MenuItem item) {
mInSearchMode = true;
return true;
}
@Override
public boolean onMenuItemActionCollapse(final MenuItem item) {
mInSearchMode = false;
return true;
}
代码示例来源:origin: sheimi/SGit
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.repo_detail, menu);
mSearchItem = menu.findItem(R.id.action_search);
mSearchItem.setOnActionExpandListener(mTabItemPagerAdapter);
mSearchItem.setVisible(mSelectedTab == COMMITS_FRAGMENT_INDEX);
SearchView searchView = (SearchView) mSearchItem.getActionView();
if (searchView != null) {
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(mTabItemPagerAdapter);
}
return true;
}
代码示例来源:origin: sheimi/SGit
public void configSearchAction(MenuItem searchItem) {
SearchView searchView = (SearchView) searchItem.getActionView();
if (searchView == null)
return;
SearchListener searchListener = new SearchListener();
searchItem.setOnActionExpandListener(searchListener);
searchView.setIconifiedByDefault(true);
searchView.setOnQueryTextListener(searchListener);
}
内容来源于网络,如有侵权,请联系作者删除!