Java Code Examples for android.support.v7.widget.Toolbar#setOnMenuItemClickListener()
The following examples show how to use
android.support.v7.widget.Toolbar#setOnMenuItemClickListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadWatcherFragment.java From United4 with GNU General Public License v3.0 | 6 votes |
/** * Adds the Refresh button to the toolbar * @param toolbar the toolbar to add the item to */ public static void addOptions(Toolbar toolbar) { toolbar.setTitle("Thread Watcher"); toolbar.getMenu().clear(); toolbar.inflateMenu(R.menu.refresh_button); toolbar.inflateMenu(R.menu.thread_watcher_menu); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int i = item.getItemId(); if (i == R.id.clear_closed) { com.angryburg.uapp.API.Thread[] threads = ThreadWatcher.threads; for (com.angryburg.uapp.API.Thread t : threads) { if (t != null && t.is_locked) ThreadWatcher.unwatchThread(t.post_id); } return true; } else if (i == R.id.refresh) { ThreadWatcher.refreshAll(); return true; } return false; } }); }
Example 2
Source File: PropertiesListFragment.java From United4 with GNU General Public License v3.0 | 6 votes |
/** * adds a close button to the menu bar * @param toolbar the toolbar */ public void addOptions(Toolbar toolbar) { toolbar.setTitle(R.string.app_name); toolbar.getMenu().clear(); toolbar.inflateMenu(R.menu.back_item); toolbar.inflateMenu(R.menu.add_property); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.add_property) { Bundle args = new Bundle(); args.putString("create", "true"); ((HiddenSettingsActivity) getActivity()).push(HiddenSettingsActivity.FragmentType.PROPERTY_EDITOR_NEW, args); } else { getActivity().finish(); } return true; } }); }
Example 3
Source File: CropAndRotate.java From text-scanner with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crop_and_rotate); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ViewCompat.setElevation(toolbar,10); toolbar.setOnMenuItemClickListener(this); Intent intent = getIntent(); message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); cropImageView = (CropImageView) findViewById(R.id.cropImageView); cropImageView.setImageUriAsync(Uri.parse(message)); mFab = (FloatingActionButton) findViewById(R.id.nextStep); mFab.setOnClickListener(this); }
Example 4
Source File: CaptureListFragment.java From CapturePacket with MIT License | 5 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { if (mRootView == null) { mRootView = inflater.inflate(R.layout.fragment_capture_list, container, false); Toolbar toolBar = mRootView.findViewById(R.id.tool_bar); toolBar.inflateMenu(R.menu.capture_list_bar); toolBar.setOnMenuItemClickListener(this); MenuItem item = toolBar.getMenu().findItem(R.id.filter); mSearchView = (SearchView) item.getActionView(); mSearchView.setQueryHint("过滤Url"); mSearchView.setOnQueryTextListener(this); mRecyclerView = mRootView.findViewById(R.id.recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(null,LinearLayoutManager.VERTICAL,false)); mHandler = new RefreshHandler(this); mAdapter = new CaptureListAdapter(); if (mCaptureBinder != null) { mAdapter.setHarEntries(mCaptureBinder.getHarEntries()); } mRecyclerView.setAdapter(mAdapter); EntryTabDelegate tabDelegate = new EntryTabDelegate((TabLayout) mRootView.findViewById(R.id.tab), (ViewGroup) mRootView.findViewById(R.id.fl_detail)); tabDelegate.setRefreshHandler(mHandler); mAdapter.setEntryTabDelegate(tabDelegate); } return mRootView; }
Example 5
Source File: MessageActivity.java From Atomic with GNU General Public License v3.0 | 5 votes |
/** * On create */ @Override public void onCreate(Bundle savedInstanceState) { setTheme(R.style.AppDialogTheme); super.onCreate(savedInstanceState); setContentView(R.layout.message); MessageRenderParams tmpParams = App.getSettings().getRenderParams(); tmpParams.messageColors = false; tmpParams.colorScheme = "default"; tmpParams.smileys = false; tmpParams.icons = false; tmpParams.messageColors = false; tmpParams.useDarkScheme = true; viewedMessage = getIntent().getExtras().getParcelable(Extra.MESSAGE); Toolbar tb = (Toolbar)findViewById(R.id.toolbar); tb.inflateMenu(R.menu.messageops); tb.setOnMenuItemClickListener(this); messageView = (TextView)findViewById(R.id.message); messageView.setBackgroundColor(Color.BLACK); CharSequence msgSequence = Message.render(viewedMessage, tmpParams); messageView.setText(msgSequence); }
Example 6
Source File: ColorPickerFragment.java From United4 with GNU General Public License v3.0 | 5 votes |
/** * adds a close button to the menu bar * * @param toolbar the toolbar */ public void addOptions(Toolbar toolbar) { toolbar.getMenu().clear(); toolbar.inflateMenu(R.menu.back_item); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { getActivity().finish(); return true; } }); }
Example 7
Source File: DebugSettingsListFragment.java From United4 with GNU General Public License v3.0 | 5 votes |
/** * adds a close button to the menu bar * @param toolbar the toolbar */ public void addOptions(Toolbar toolbar) { toolbar.setTitle(R.string.app_name); toolbar.getMenu().clear(); toolbar.inflateMenu(R.menu.debug_menu); toolbar.inflateMenu(R.menu.back_item); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { //noinspection SwitchStatementWithoutDefaultBranch switch (item.getItemId()) { case R.id.back_item: getActivity().finish(); return true; case R.id.reload_all: NotifierService.notify(NotifierService.NotificationType.RELOAD_ALL); return true; case R.id.reload_index: NotifierService.notify(NotifierService.NotificationType.RELOAD_INDEX); return true; case R.id.reload_music: NotifierService.notify(NotifierService.NotificationType.RELOAD_MUSIC); return true; case R.id.invalidate_toolbar: ((HiddenSettingsActivity) getActivity()).invalidateToolbarColor(); NotifierService.notify(NotifierService.NotificationType.INVALIDATE_TOOLBAR); return true; } return false; } }); }
Example 8
Source File: ActivityPlayer.java From uPods-android with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); toolbar = (Toolbar) findViewById(R.id.toolbar_player); toolbar.setTitleTextColor(getResources().getColor(R.color.white)); toolbar.inflateMenu(R.menu.menu_activity_player); toolbar.setOnMenuItemClickListener(this); toolbar.setVisibility(View.VISIBLE); itemFavorites = (ActionMenuItemView) toolbar.findViewById(R.id.action_favorites_player); currentMediaItem = UniversalPlayer.getInstance().getPlayingMediaItem(); if (currentMediaItem == null) { Toast.makeText(this, getString(R.string.error_cant_play), Toast.LENGTH_SHORT).show(); onBackPressed(); return; } if (getFragmentManager().getBackStackEntryCount() == 0) { if (currentMediaItem instanceof Podcast && MediaUtils.isVideoUrl(currentMediaItem.getAudeoLink())) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); FragmentVideoPlayer fragmentVideoPlayer = new FragmentVideoPlayer(); fragmentVideoPlayer.setOnPlayingFailedCallback(MediaUtils.getPlayerFailCallback(this, currentMediaItem)); showFragment(R.id.fl_window, fragmentVideoPlayer, FragmentVideoPlayer.TAG); } else { fragmentPlayer = new FragmentPlayer(); fragmentPlayer.setPlayableItem(currentMediaItem); showFragment(R.id.fl_window, fragmentPlayer, FragmentMainFeatured.TAG); } } }
Example 9
Source File: HiddenThreadListFragment.java From United4 with GNU General Public License v3.0 | 5 votes |
/** * Adds the back button to the toolbar * @param toolbar the toolbar to add the item to */ public void addOptions(Toolbar toolbar) { toolbar.setTitle("Thread Watcher"); toolbar.getMenu().clear(); toolbar.inflateMenu(R.menu.back_item); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { HiddenThreadListFragment.this.getActivity().finish(); return true; } }); }
Example 10
Source File: AccountSettingsActivity.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent(); Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); root.addView(bar, 0); // insert at top bar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); bar.inflateMenu(R.menu.menu_account_settings); bar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem arg0) { if(arg0.getItemId() == R.id.menu_delete){ deleteAccount(); } else if(arg0.getItemId() == R.id.menu_migrate) { migrateAccount (); } return false; } }); }
Example 11
Source File: BlurActivity.java From UPMiss with GNU General Public License v3.0 | 5 votes |
protected void onInitToolBar() { // SetBar mToolbar = (Toolbar) findViewById(R.id.toolbar); if (mToolbar == null) return; mToolbar.setOnMenuItemClickListener(this); onInflateMenu(mToolbar); }
Example 12
Source File: ImageCropActivity.java From PhotoEdit with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crop_image); mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.inflateMenu(R.menu.menu_crop); mToolbar.setOnMenuItemClickListener(this); Intent intent = getIntent(); mPath = intent.getStringExtra("camera_path"); Bitmap bit = BitmapFactory.decodeFile(mPath); cropImage = (CropImageView) findViewById(R.id.cropmageView); cancleBtn = (ImageButton) findViewById(R.id.btn_cancel); cancleBtn.setOnClickListener(this); okBtn = (ImageButton) findViewById(R.id.btn_ok); okBtn.setOnClickListener(this); Bitmap hh = BitmapFactory.decodeResource(this.getResources(), R.drawable.crop_button); cropImage.setCropOverlayCornerBitmap(hh); cropImage.setImageBitmap(bit); // Bitmap bit = // BitmapFactory.decodeResource(this.getResources(),R.drawable.hi0); cropImage.setGuidelines(CropImageType.CROPIMAGE_GRID_ON_TOUCH);// 触摸时显示网格 cropImage.setFixedAspectRatio(false);// 自由剪切 }
Example 13
Source File: MainActivity.java From batteryhub with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); // Add the search button to the toolbar. Toolbar toolbar = getActionBarToolbar(); toolbar.inflateMenu(R.menu.menu_main); toolbar.setOnMenuItemClickListener(this); return true; }
Example 14
Source File: BaseActivity.java From RetailStore with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); if (this instanceof CartActivity) { return true; } this.menu = menu; // Add the filter & search buttons to the toolbar. Toolbar toolbar = getActionBarToolbar(); toolbar.inflateMenu(R.menu.home_act_filtered); toolbar.setOnMenuItemClickListener(this); cartPresenter.countCartItems(); return true; }
Example 15
Source File: MainActivity.java From ghwatch with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate() intent: " + getIntent()); if (savedInstanceState != null) { filterByRepository = savedInstanceState.getString(STATE_FILTER_REPOSITORY); } setContentView(R.layout.activity_main); imageLoader = ImageLoader.getInstance(getApplicationContext()); unreadNotificationsService = new UnreadNotificationsService(getBaseContext()); initNavigationDrawer(R.id.nav_unread); repositoriesListViewTablet = (ListView) findViewById(R.id.repositories_list); if (repositoriesListViewTablet != null) repositoriesListViewTablet.setOnItemClickListener(new RepositoriesListItemClickListener()); // initialization of main content notificationsListView = (ListView) findViewById(R.id.list); notificationsListView.setVerticalFadingEdgeEnabled(true); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(notificationsListView, new NotificationsListSwipeDismissListener()); notificationsListView.setOnTouchListener(touchListener); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. notificationsListView.setOnScrollListener(touchListener.makeScrollListener()); Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbar_bottom); if (toolbarBottom != null) { toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); if (repositoriesListViewTablet == null) toolbarBottom.inflateMenu(R.menu.main_activity_toolbar); else toolbarBottom.inflateMenu(R.menu.main_activity_toolbar_tablet); } initSwipeLayout(this); }
Example 16
Source File: ToolbarContentTintHelper.java From APlayer with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public static void setToolbarContentColor(@NonNull Context context, Toolbar toolbar, @Nullable Menu menu, final @ColorInt int toolbarContentColor, final @ColorInt int titleTextColor, final @ColorInt int subtitleTextColor, final @ColorInt int menuWidgetColor) { if (toolbar == null) { return; } if (menu == null) { menu = toolbar.getMenu(); } toolbar.setTitleTextColor(titleTextColor); toolbar.setSubtitleTextColor(subtitleTextColor); if (toolbar.getNavigationIcon() != null) { // Tint the toolbar navigation icon (e.g. back, drawer, etc.) toolbar.setNavigationIcon( TintHelper.createTintedDrawable(toolbar.getNavigationIcon(), toolbarContentColor)); } InternalToolbarContentTintUtil.tintMenu(toolbar, menu, toolbarContentColor); InternalToolbarContentTintUtil.applyOverflowMenuTint(context, toolbar, menuWidgetColor); if (context instanceof Activity) { InternalToolbarContentTintUtil .setOverflowButtonColor((Activity) context, toolbarContentColor); } try { // Tint immediate overflow menu items final Field menuField = Toolbar.class.getDeclaredField("mMenuBuilderCallback"); menuField.setAccessible(true); final Field presenterField = Toolbar.class.getDeclaredField("mActionMenuPresenterCallback"); presenterField.setAccessible(true); final Field menuViewField = Toolbar.class.getDeclaredField("mMenuView"); menuViewField.setAccessible(true); final MenuPresenter.Callback currentPresenterCb = (MenuPresenter.Callback) presenterField .get(toolbar); if (!(currentPresenterCb instanceof ATHMenuPresenterCallback)) { final ATHMenuPresenterCallback newPresenterCb = new ATHMenuPresenterCallback(context, menuWidgetColor, currentPresenterCb, toolbar); final MenuBuilder.Callback currentMenuCb = (MenuBuilder.Callback) menuField.get(toolbar); toolbar.setMenuCallbacks(newPresenterCb, currentMenuCb); ActionMenuView menuView = (ActionMenuView) menuViewField.get(toolbar); if (menuView != null) { menuView.setMenuCallbacks(newPresenterCb, currentMenuCb); } } // OnMenuItemClickListener to tint submenu items final Field menuItemClickListener = Toolbar.class .getDeclaredField("mOnMenuItemClickListener"); menuItemClickListener.setAccessible(true); Toolbar.OnMenuItemClickListener currentClickListener = (Toolbar.OnMenuItemClickListener) menuItemClickListener .get(toolbar); if (!(currentClickListener instanceof ATHOnMenuItemClickListener)) { final ATHOnMenuItemClickListener newClickListener = new ATHOnMenuItemClickListener(context, menuWidgetColor, currentClickListener, toolbar); toolbar.setOnMenuItemClickListener(newClickListener); } } catch (Exception e) { e.printStackTrace(); } }
Example 17
Source File: TableLayoutFragment.java From AdaptiveTableLayout with MIT License | 4 votes |
@Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_tab_layout, container, false); mTableLayout = view.findViewById(R.id.tableLayout); progressBar = view.findViewById(R.id.progressBar); vHandler = view.findViewById(R.id.vHandler); Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Objects.requireNonNull(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; }
Example 18
Source File: ToolbarActivity.java From AndroidViewDemo with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac_toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.ac_toolbar_toolbar); // 设置主标题及其颜色 toolbar.setTitle("AndroidViewDemo"); toolbar.setTitleTextColor(Color.WHITE); // 设置次标题及其颜色 toolbar.setSubtitle("AigeStudio"); toolbar.setSubtitleTextColor(Color.LTGRAY); // 设置导航按钮 toolbar.setNavigationIcon(R.drawable.menu); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(ToolbarActivity.this, "Navigation", Toast.LENGTH_SHORT).show(); } }); // 设置Logo图标 toolbar.setLogo(R.mipmap.ic_launcher); // 设置菜单及其点击监听 toolbar.inflateMenu(R.menu.ac_toolbar_menu); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { String result = ""; switch (item.getItemId()) { case R.id.ac_toolbar_copy: result = "Copy"; break; case R.id.ac_toolbar_cut: result = "Cut"; break; case R.id.ac_toolbar_del: result = "Del"; break; case R.id.ac_toolbar_edit: result = "Edit"; break; case R.id.ac_toolbar_email: result = "Email"; break; } Toast.makeText(ToolbarActivity.this, result, Toast.LENGTH_SHORT).show(); return true; } }); }
Example 19
Source File: PostFragment.java From Nimingban with Apache License 2.0 | 4 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup view = (ViewGroup) inflater.inflate(R.layout.activity_toolbar, container, false); ViewGroup contentPanel = (ViewGroup) view.findViewById(R.id.content_panel); ViewGroup contentView = (ViewGroup) inflater.inflate(R.layout.fragment_post, contentPanel, true); mToolbar = (Toolbar) view.findViewById(R.id.toolbar); // I like hardcode mToolbar.setSubtitle("A岛·adnmb.com"); if (mId != null) { mToolbar.setTitle(mSite.getPostTitle(getContext(), mId)); } else { mToolbar.setTitle(getString(R.string.thread)); } mToolbar.setNavigationIcon(DrawableManager.getDrawable(getContext(), R.drawable.v_arrow_left_dark_x24)); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getFragmentHost().finishFragment(PostFragment.this); } }); mToolbar.inflateMenu(R.menu.activity_post); mToolbar.setOnMenuItemClickListener(this); mContentLayout = (ContentLayout) contentView.findViewById(R.id.content_layout); mRecyclerView = mContentLayout.getRecyclerView(); mReplyHelper = new ReplyHelper(); mReplyHelper.setEmptyString(getString(R.string.not_found)); mContentLayout.setHelper(mReplyHelper); if (Settings.getFastScroller()) { mContentLayout.showFastScroll(); } else { mContentLayout.hideFastScroll(); } mReplyAdapter = new ReplyAdapter(); mRecyclerView.setAdapter(mReplyAdapter); mRecyclerView.setSelector(Ripple.generateRippleDrawable( getContext(), ResourcesUtils.getAttrBoolean(getContext(), R.attr.dark))); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.setOnItemClickListener(this); mRecyclerView.setOnItemLongClickListener(this); mRecyclerView.hasFixedSize(); mOnScrollListener = new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (RecyclerView.SCROLL_STATE_DRAGGING == newState) { pauseHolders(); } else if (RecyclerView.SCROLL_STATE_IDLE == newState) { resumeHolders(); } } }; mRecyclerView.addOnScrollListener(mOnScrollListener); mOpColor = getResources().getColor(R.color.colorAccent); // Refresh mReplyHelper.firstRefresh(); Messenger.getInstance().register(Constants.MESSENGER_ID_REPLY, this); Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this); isLoaded = false; return view; }
Example 20
Source File: ToolBarUtil.java From Android-Architecture with Apache License 2.0 | 2 votes |
/** * 向Toolbar添加menu,一般fragment使用 * * @param toolbar * @param layout * @param itemClickListener */ public static void addMenu(Toolbar toolbar, int layout, Toolbar.OnMenuItemClickListener itemClickListener) { if (toolbar == null) return; toolbar.inflateMenu(layout); toolbar.setOnMenuItemClickListener(itemClickListener); }