本文整理汇总了Java中android.support.v4.view.MenuItemCompat类的典型用法代码示例。如果您正苦于以下问题:Java MenuItemCompat类的具体用法?Java MenuItemCompat怎么用?Java MenuItemCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MenuItemCompat类属于android.support.v4.view包,在下文中一共展示了MenuItemCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restoreActionViewStates
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
public void restoreActionViewStates(Bundle states) {
if (states != null) {
SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());
int itemCount = size();
for (int i = 0; i < itemCount; i++) {
MenuItem item = getItem(i);
View v = MenuItemCompat.getActionView(item);
if (!(v == null || v.getId() == -1)) {
v.restoreHierarchyState(viewStates);
}
if (item.hasSubMenu()) {
((SubMenuBuilder) item.getSubMenu()).restoreActionViewStates(states);
}
}
int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
if (expandedId > 0) {
MenuItem itemToExpand = findItem(expandedId);
if (itemToExpand != null) {
MenuItemCompat.expandActionView(itemToExpand);
}
}
}
}
示例2: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
/*简单查询*/
final MenuItem item = menu.findItem(R.id.action_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(item);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
paraMap.put("keyWord", query);
showLoading();
refresh = true;
presenter.getData(1, SIZE, paraMap);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return true;
}
示例3: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
final MenuItem item = menu.findItem(R.id.action_search);
SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(item);
mSearchView.setIconifiedByDefault(true);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (shouldShowFAQ)
((Searchable) currentFragment).setSearchText(newText);
return true;
}
});
return super.onCreateOptionsMenu(menu);
}
示例4: onOptionsItemSelected
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
startActivity(new Intent(App.getAppContext(),Settings.class));
return true;
}else if (id == R.id.action_favorite) {
favourite(post);
}else if (id == R.id.action_share) {
shareTextUrl();
}
return super.onOptionsItemSelected(item);
}
示例5: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.share, menu);
MenuItem item = menu.findItem(R.id.action_share);
ShareActionProvider shareAction = (ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent send = new Intent();
send.setAction(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_TEXT, text.toString());
send.setType("text/plain");
if(shareAction != null) {
shareAction.setShareIntent(send);
}
return super.onCreateOptionsMenu(menu);
}
示例6: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.ride_menu, menu);
// store action provider
shareMenuItem = menu.findItem(R.id.menu_item_share);
shareMenuItem.setVisible(false);
shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);
// Create share intent
shareFileIntent = new Intent();
shareFileIntent.setAction(Intent.ACTION_SEND);
shareFileIntent.setType("text/csv");
shareFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setShareIntent(shareFileIntent);
return true;
}
示例7: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.poem_toolbar, menu);
favoriteItem = menu.findItem(R.id.action_addToFavorites);
if (presenter.isFavorite()){
favoriteItem.setIcon(R.drawable.ic_star_full);
}
MenuItem item = menu.findItem(R.id.action_share);
ShareActionProvider mShareActionProvider =
(ShareActionProvider) MenuItemCompat.getActionProvider(item);
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, presenter.getPoemContentString());
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
示例8: onPrepareOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean res = super.onPrepareOptionsMenu(menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
getWebViewCoordinator().onQueryByText(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return res;
}
示例9: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
MenuItem search = menu.findItem(R.id.search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override public boolean onQueryTextSubmit(String query) {
getSupportActionBar().setSubtitle("found: "+mAdapter.getItemCount());
return true;
}
@Override public boolean onQueryTextChange(String newText) {
if (mAdapter != null) {
mAdapter.getFilter().filter(newText);
}
return true;
}
});
menu.findItem(R.id.action_settings).setIntent(new Intent(this,SettingsActivity.class));
return true;
}
示例10: fillApplicationList
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
private void fillApplicationList() {
// Get recycler view
final RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
rvApplication.setHasFixedSize(true);
rvApplication.setLayoutManager(new LinearLayoutManager(this));
// Get/set application list
new AsyncTask<Object, Object, List<Rule>>() {
@Override
protected List<Rule> doInBackground(Object... arg) {
return Rule.getRules(ActivityMain.this);
}
@Override
protected void onPostExecute(List<Rule> result) {
if (running) {
if (searchItem != null)
MenuItemCompat.collapseActionView(searchItem);
adapter = new RuleAdapter(result, ActivityMain.this);
rvApplication.setAdapter(adapter);
}
}
}.execute();
}
示例11: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.latest_menu, menu);
getMenuInflater().inflate(R.menu.filter_menu, menu);
MenuItem searchViewItem = menu.findItem(R.id.filter_keyword);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
filter.filter("K:" + searchView.getQuery());
searchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
filter.filter("K:" + searchView.getQuery());
return false;
}
});
return true;
}
示例12: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的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;
}
示例13: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// Inflate the menu and configure the media router action provider.
getMenuInflater().inflate(R.menu.media_route_menu_item, menu);
// Attach the MediaRouteSelector to the menu item
MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
MediaRouteActionProvider mediaRouteActionProvider =
(MediaRouteActionProvider)MenuItemCompat.getActionProvider(
mediaRouteMenuItem);
// Attach the MediaRouteSelector that you built in onCreate()
mediaRouteActionProvider.setRouteSelector(mSelector);
// Return true to show the menu.
return true;
}
示例14: onCreateOptionsMenu
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
/*简单查询*/
final MenuItem item = menu.findItem(R.id.action_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(item);
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
Intent intent = new Intent("Msg_KeyWord");
intent.putExtra("keyWord", query);
sendBroadcast(intent);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return true;
}
示例15: getFocus
import android.support.v4.view.MenuItemCompat; //导入依赖的package包/类
private void getFocus() {
getView().setFocusableInTouchMode(true);
getView().requestFocus();
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
if (MenuItemCompat.isActionViewExpanded(search)) {
MenuItemCompat.collapseActionView(search);
return true;
} else
return false;
}
return false;
}
});
}