本文整理汇总了Java中android.support.v7.widget.Toolbar.setOnMenuItemClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java Toolbar.setOnMenuItemClickListener方法的具体用法?Java Toolbar.setOnMenuItemClickListener怎么用?Java Toolbar.setOnMenuItemClickListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.Toolbar
的用法示例。
在下文中一共展示了Toolbar.setOnMenuItemClickListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// App Logo
toolbar.setLogo(R.drawable.ic_launcher);
// Title
toolbar.setTitle("My Title");
// Sub Title
toolbar.setSubtitle("Sub title");
setSupportActionBar(toolbar);
// Navigation Icon 要設定在 setSupoortActionBar 才有作用
// 否則會出現 back bottom
toolbar.setNavigationIcon(R.drawable.ab_android);
// Menu item click 的監聽事件一樣要設定在 setSupportActionBar 才有作用
toolbar.setOnMenuItemClickListener(onMenuItemClick);
}
示例2: onCreate
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setHasFixedSize(true);
if (savedInstanceState == null) {
mHorizontal = true;
} else {
mHorizontal = savedInstanceState.getBoolean(ORIENTATION);
}
setupAdapter();
}
示例3: setupHeaderView
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void setupHeaderView() {
final Toolbar toolbar = new Toolbar(this);
getMenuInflater().inflate(R.menu.header_menu, toolbar.getMenu());
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem item) {
handleToolbarItemClick(item);
return true;
}
});
header = new ToolbarHeader(this);
header.setToolbar(toolbar);
header.setBackgroundColor(Color.WHITE);
final Bitmap defaultArtwork = BitmapFactory.decodeResource(getResources(), R.raw
.default_artwork);
final DisplayableDefaults defaults = new ImmutableDisplayableDefaults("Playlist",
"Unknown artists",
new BitmapDrawable(getResources(), defaultArtwork));
header.setTitleDataBinder(new TitleBinder(headerTitleCache, defaults));
header.setSubtitleDataBinder(new SubtitleBinder(headerSubtitleCache, defaults));
header.setArtworkDataBinder(new ArtworkBinder(headerArtworkCache, defaults));
}
示例4: inflateToolbarMenu
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
* Inflates the menu of the toolbar, which is shown, when the tab switcher is shown.
*/
private void inflateToolbarMenu() {
Toolbar[] toolbars = getToolbars();
int menuId = getModel().getToolbarMenuId();
if (toolbars != null && menuId != -1) {
Toolbar toolbar = toolbars.length > 1 ? toolbars[1] : toolbars[0];
toolbar.inflateMenu(menuId);
toolbar.setOnMenuItemClickListener(getModel().getToolbarMenuItemListener());
}
}
示例5: onCreateView
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_tab_layout, container, false);
mTableLayout = (AdaptiveTableLayout) view.findViewById(R.id.tableLayout);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
vHandler = view.findViewById(R.id.vHandler);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().onBackPressed();
}
});
toolbar.inflateMenu(R.menu.table_layout);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.actionSave) {
applyChanges();
} else if (item.getItemId() == R.id.actionSettings) {
SettingsDialog.newInstance(
mTableLayout.isHeaderFixed(),
mTableLayout.isSolidRowHeader(),
mTableLayout.isRTL(),
mTableLayout.isDragAndDropEnabled())
.show(getChildFragmentManager(), SettingsDialog.class.getSimpleName());
}
return true;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// mTableLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
initAdapter();
return view;
}
示例6: onCreateOptionsMenu
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// Add the search button to the toolbar.
Toolbar toolbar = getActionBarToolbar();
toolbar.inflateMenu(R.menu.explore_io_menu);
toolbar.setOnMenuItemClickListener(this);
return true;
}
示例7: setupView
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void setupView() {
createPoiFeature = (TextView) getActivity().findViewById(R.id.createPoiFeature);
createPoiFeature.setOnClickListener(clickListener);
createName = (EditText) getActivity().findViewById(R.id.createName);
createStreet = (EditText) getActivity().findViewById(R.id.createStreet);
createHouseNumber = (EditText) getActivity().findViewById(R.id.createHouseNumber);
createPostCode = (EditText) getActivity().findViewById(R.id.createPostCode);
createCity = (EditText) getActivity().findViewById(R.id.createCity);
createPhone = (EditText) getActivity().findViewById(R.id.createPhone);
createWebsite = (EditText) getActivity().findViewById(R.id.createWebsite);
createEmail = (EditText) getActivity().findViewById(R.id.createEmail);
createInternetContainer = (LinearLayout) getActivity().findViewById(R.id.createInternetContainer);
createInternet = (Spinner) getActivity().findViewById(R.id.createInternet);
dropdownItems = new String[]{"", getString(R.string.yes), getString(R.string.no), getString(R.string.wifi), getString(R.string.wired), getString(R.string.wlan)};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, dropdownItems);
createInternet.setAdapter(adapter);
TextView osmCopyright = (TextView) getActivity().findViewById(R.id.osmCopyrightCreatePoi);
osmCopyright.setText(Html.fromHtml(getString(R.string.osm_copyright)));
toolbar = (Toolbar) getActivity().findViewById(R.id.createPoiToolbar);
toolbar.setNavigationOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
closeFragment();
}
});
toolbar.inflateMenu(R.menu.update_poi);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (!allFieldsValid()) return true;
createPoi();
return true;
}
});
}
示例8: initView
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void initView() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setTe = (TextView) findViewById(R.id.receive);
onLineListView = (RecyclerView) findViewById(R.id.online_list);
onlineRecyclerAdapter = new OnlineRecyclerAdapter();
onlineRecyclerAdapter.setOnItemClickListener(new OnlineRecyclerAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position, final OnlineModel onlineModel) {
Toast.makeText(App.context, "发送消息 desIp=" + onlineModel.getSourceIp(), Toast.LENGTH_SHORT).show();
SendOperation.getInstance().sendMessage(MessageModel.createMessage(MessageModel.SEND_INFO, onlineModel.getSourceIp(),
new SendInfo().getJsonString()), 10);
}
});
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
onLineListView.setLayoutManager(layoutManager);
onLineListView.setItemAnimator(new DefaultItemAnimator());
onLineListView.setAdapter(onlineRecyclerAdapter);
toolbar.inflateMenu(R.menu.base_toolbar_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int menuId = item.getItemId();
if (menuId == R.id.action_setting) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), 0xaa);
} catch (android.content.ActivityNotFoundException ex) {
}
}
return true;
}
});
}
示例9: onCreateOptionsMenu
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// Add the filter & search buttons to the toolbar.
Toolbar toolbar = getActionBarToolbar();
toolbar.inflateMenu(R.menu.explore_sessions_filtered);
toolbar.setOnMenuItemClickListener(this);
return true;
}
示例10: onCreateView
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContext = getContext();
View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
mToolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
mToolbar.inflateMenu(R.menu.menu_profile);
mToolbar.setOnMenuItemClickListener(this);
mImageProfile = (CircleImageView) rootView.findViewById(R.id.image_profile);
mTextViewFullName = (TextView) rootView.findViewById(R.id.text_fullname);
Glide.with(mContext).load(Quire.userProfilePic).into(mImageProfile);
mTextViewFullName.setText(Quire.name);
mImageUpload = (ImageView) rootView.findViewById(R.id.image_one);
mImageUpload.setOnClickListener(this);
mButtonListNewItem = (Button) rootView.findViewById(R.id.button_list_new_item);
mButtonListNewItem.setOnClickListener(this);
mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
userListingsAdapter = new UserListingsAdapter(mContext, userListingsData());
mRecyclerView.setAdapter(userListingsAdapter);
mLayoutManager = new GridLayoutManager(mContext, 3);
// mLayoutManager = new LinearLayoutManager(mContext);
mRecyclerView.setLayoutManager(mLayoutManager);
return rootView;
}
示例11: initToolBar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
* 初始化toolbar
*/
private void initToolBar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.tb_bar);
toolbar.setTitleTextColor(Color.WHITE);
toolbar.setTitle("状态切换");
toolbar.inflateMenu(R.menu.base_toolbar_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if(item.getItemId() == R.id.action_contents) {
showContent();
}
if(item.getItemId() == R.id.action_emptyData) {
showEmptyData();
}
if(item.getItemId() == R.id.action_error) {
showError();
}
if(item.getItemId() == R.id.action_networkError) {
showNetWorkError();
}
if(item.getItemId() == R.id.action_loading) {
showLoading();
}
return true;
}
});
}
示例12: initToolBar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void initToolBar(Toolbar toolbarDoubanDetail, String title) {
setSupportActionBar(toolbarDoubanDetail);
toolbarDoubanDetail.setTitle(title);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//去除默认Title显示
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.mipmap.icon_back);
}
toolbarDoubanDetail.setTitleTextColor(Color.WHITE);
toolbarDoubanDetail.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
toolbarDoubanDetail.setTitleTextAppearance(this, R.style.ToolBar_Title);
toolbarDoubanDetail.setSubtitleTextAppearance(this, R.style.Toolbar_SubTitle);
toolbarDoubanDetail.inflateMenu(R.menu.base_header_menu);
toolbarDoubanDetail.setOverflowIcon(getDrawable(R.mipmap.actionbar_more));
toolbarDoubanDetail.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.actionbar_more:// 更多信息
setTitleClickMore();
break;
}
return true;
}
});
}
示例13: initView
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override protected void initView(View parent) {
requestBaseInit(getPageTitle());
mRecyclerView = (RecyclerView) parent.findViewById(R.id.recyclerView);
Toolbar toolbar = getToolBar();
toolbar.inflateMenu(R.menu.main);
toolbar.setBackgroundResource(R.color.main_color_normal);
toolbar.setOnMenuItemClickListener(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setHasFixedSize(true);
setupAdapter();
}
示例14: getSelectorModeToolbar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
static Toolbar getSelectorModeToolbar(Context context,
View.OnClickListener onClickListener,
Toolbar.OnMenuItemClickListener onItemClickListener) {
final Toolbar toolbar = new Toolbar(context);
toolbar.setTag(SELECTOR_TOOLBAR_TAG);
Theme theme = Settings.getInstance(context).getThemeInstance(context);
int accentColor = theme.getAccentColor(context);
int accentTextColor = theme.getAccentTextColor(context);
toolbar.setBackgroundColor(accentColor);
toolbar.setTitleTextColor(accentTextColor);
toolbar.inflateMenu(R.menu.selector_mode);
toolbar.setOnMenuItemClickListener(onItemClickListener);
Drawable menuIcon = toolbar.getOverflowIcon();
if (menuIcon != null) {
DrawableCompat.wrap(menuIcon);
DrawableCompat.setTint(menuIcon.mutate(), accentTextColor);
}
Drawable navIcon = ContextCompat.getDrawable(context,
R.drawable.ic_clear_black_24dp);
if (navIcon != null) {
DrawableCompat.wrap(navIcon);
DrawableCompat.setTint(navIcon.mutate(), accentTextColor);
toolbar.setNavigationIcon(navIcon);
}
toolbar.setNavigationOnClickListener(onClickListener);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
toolbar.setElevation(context.getResources()
.getDimension(R.dimen.toolbar_elevation));
}
return toolbar;
}
示例15: requestFullScreenIfLandscape
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void requestFullScreenIfLandscape() {
if (getResources().getBoolean(R.bool.landscape)) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
} else {
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.main);
toolbar.setOnMenuItemClickListener(this);
}
}