Java Code Examples for androidx.appcompat.widget.Toolbar#inflateMenu()
The following examples show how to use
androidx.appcompat.widget.Toolbar#inflateMenu() .
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: ProfileManagerActivity.java From Maying with Apache License 2.0 | 6 votes |
/** * init toolbar */ private void initToolbar() { Toolbar toolbar = findViewById(R.id.toolbar); toolbar.setTitle(R.string.profiles); toolbar.setNavigationIcon(R.drawable.ic_navigation_close); toolbar.setNavigationOnClickListener(v -> { Intent intent = getParentActivityIntent(); if (shouldUpRecreateTask(intent) || isTaskRoot()) { TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(intent).startActivities(); } else { finish(); } }); toolbar.inflateMenu(R.menu.profile_manager_menu); toolbar.setOnMenuItemClickListener(this); }
Example 2
Source File: FragmentSB.java From Pixiv-Shaft with MIT License | 6 votes |
@Override public void initToolbar(Toolbar toolbar) { super.initToolbar(toolbar); toolbar.inflateMenu(R.menu.add_tag); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.action_add) { AddTagDialog dialog = AddTagDialog.newInstance(0); dialog.show(getChildFragmentManager(), "AddTagDialog"); return true; } return false; } }); }
Example 3
Source File: ProfileManagerActivity.java From ShadowsocksRR with Apache License 2.0 | 6 votes |
/** * init toolbar */ private void initToolbar() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle(R.string.profiles); toolbar.setNavigationIcon(R.drawable.ic_navigation_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = getParentActivityIntent(); if (shouldUpRecreateTask(intent) || isTaskRoot()) { TaskStackBuilder.create(ProfileManagerActivity.this).addNextIntentWithParentStack(intent).startActivities(); } else { finish(); } } }); toolbar.inflateMenu(R.menu.profile_manager_menu); toolbar.setOnMenuItemClickListener(this); }
Example 4
Source File: MainActivity.java From HeaderView with MIT License | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); toolbar.setTitle(getString(R.string.app_name)); toolbar.inflateMenu(R.menu.menu_main); toolbar.setOnMenuItemClickListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); } findViewById(R.id.normal_drawer).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, NormalHeaderActivity.class))); findViewById(R.id.compact_drawer).setOnClickListener(v -> startActivity(new Intent(MainActivity.this, CompactHeaderActivity.class))); }
Example 5
Source File: AbstractTabSwitcherLayout.java From ChromeLikeTabSwitcher with Apache License 2.0 | 6 votes |
/** * 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[TabSwitcher.SECONDARY_TOOLBAR_INDEX] : toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX]; Menu previousMenu = toolbar.getMenu(); if (previousMenu != null) { previousMenu.clear(); } toolbar.inflateMenu(menuId); toolbar.setOnMenuItemClickListener(getModel().getToolbarMenuItemListener()); } }
Example 6
Source File: ToolbarHelper.java From Paginize with MIT License | 5 votes |
@SuppressLint("ResourceType") public static void setupMenu(Toolbar toolbar, @MenuRes int menuResId, Toolbar.OnMenuItemClickListener listener) { if (menuResId > 0) { toolbar.inflateMenu(menuResId); if (listener != null) { toolbar.setOnMenuItemClickListener(listener); } } }
Example 7
Source File: FetchPreferencesActivity.java From mage-android with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fetch_preferences); toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.inflateMenu(R.menu.fetch_preferences_menu); noContentView = findViewById(R.id.no_content_frame); boolean fetchEnabled = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getResources().getString(R.string.dataFetchEnabledKey), getResources().getBoolean(R.bool.dataFetchEnabledDefaultValue)); SwitchCompat dataEnabledSwitch = (SwitchCompat) toolbar.findViewById(R.id.toolbar_switch); dataEnabledSwitch.setChecked(fetchEnabled); dataEnabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PreferenceManager.getDefaultSharedPreferences(FetchPreferencesActivity.this).edit().putBoolean(getResources().getString(R.string.dataFetchEnabledKey), isChecked).commit(); updateView(isChecked); } }); updateView(fetchEnabled); getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, preference).commit(); }
Example 8
Source File: SingleActivity.java From PhotoDraweeView with Apache License 2.0 | 5 votes |
private void initToolbar() { Toolbar toolbar = findViewById(R.id.toolbar); toolbar.inflateMenu(R.menu.single); toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.default_image: mPhotoDraweeView.setOnDoubleTapListener(null); mPhotoDraweeView.setPhotoUri(Uri.parse("res:///" + R.drawable.panda)); break; case R.id.failure_image: mPhotoDraweeView.setPhotoUri(Uri.parse("http://google.com/404.jpg")); break; case R.id.view_pager: ViewPagerActivity.startActivity(SingleActivity.this); break; case R.id.recycler_view: RecyclerViewActivity.startActivity(SingleActivity.this); break; case R.id.scale_step: mPhotoDraweeView.setOnDoubleTapListener( new ScaleStepDoubleTapListener(mPhotoDraweeView.getAttacher(), 0.25f)); break; case R.id.shared_element: SharedElementActivity.startActivity(SingleActivity.this); break; default: break; } return true; } }); }
Example 9
Source File: DetailFragment.java From Passbook with Apache License 2.0 | 5 votes |
private void setupToolbar(View rootView, String title) { Toolbar toolbar; TextView titleView; toolbar = rootView.findViewById(R.id.toolbar); View close = rootView.findViewById(R.id.close); close.setOnClickListener(this); View header = rootView.findViewById(R.id.header); ImageButton fab = rootView.findViewById(R.id.fab); fab.setOnClickListener(this); header.setBackgroundColor(mColor); titleView = rootView.findViewById(android.R.id.title); titleView.setText(title); // Elevation to minus 1 so that fab would not be covered on 5.0 float elevation = getResources().getDimension(R.dimen.fab_small_elevation) - 0.5f; ViewCompat.setElevation(header, elevation); if(rootView.findViewById(R.id.frame_box)==null) { MainActivity ma = (MainActivity) getActivity(); if (ma != null) { ma.setStatusBarColor(mColor, 200, false); } } toolbar.inflateMenu(R.menu.menu_detail); toolbar.getMenu().getItem(0).getIcon().setColorFilter( C.ThemedColors[C.colorTextNormal], PorterDuff.Mode.SRC_ATOP); toolbar.setOnMenuItemClickListener(this); }
Example 10
Source File: SettingsActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
private void initToolbar() { Toolbar toolbar = findViewById(R.id.activity_settings_toolbar); toolbar.setTitle(getString(R.string.action_settings)); toolbar.setNavigationIcon(R.drawable.ic_toolbar_back); toolbar.setNavigationOnClickListener(view -> finish()); toolbar.inflateMenu(R.menu.activity_settings); toolbar.setOnMenuItemClickListener(this); }
Example 11
Source File: ConfigActivity.java From Daedalus with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { if (Daedalus.isDarkTheme()) { setTheme(R.style.AppTheme_Dark_NoActionBar); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_config); ConfigFragment fragment; switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) { case LAUNCH_FRAGMENT_RULE: fragment = new RuleConfigFragment(); break; case LAUNCH_FRAGMENT_DNS_SERVER: default://should never reach this fragment = new DnsServerConfigFragment(); break; } Toolbar toolbar = findViewById(R.id.toolbar_config); Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_clear); Drawable wrappedDrawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrappedDrawable, Color.WHITE); toolbar.setNavigationIcon(drawable); toolbar.setNavigationOnClickListener(v -> onBackPressed()); toolbar.setOnMenuItemClickListener(fragment); toolbar.inflateMenu(R.menu.custom_config); FragmentManager manager = getSupportFragmentManager(); fragment.setIntent(getIntent()); FragmentTransaction fragmentTransaction = manager.beginTransaction(); fragmentTransaction.replace(R.id.id_config, fragment); fragmentTransaction.commit(); }
Example 12
Source File: ImageControlFragment.java From mcumgr-android with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ButterKnife.bind(this, view); final Toolbar toolbar = view.findViewById(R.id.toolbar); toolbar.inflateMenu(R.menu.help); toolbar.setOnMenuItemClickListener(this); // This makes the layout animate when the TextView value changes. // By default it animates only on hiding./showing views. // The view must have android:animateLayoutChanges(true) attribute set in the XML. ((ViewGroup) view).getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING); }
Example 13
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 5 votes |
private void createBottomToolbar() { Toolbar bottomToolbar = (Toolbar) findViewById(R.id.bottomToolbar); bottomToolbar.inflateMenu(R.menu.menu_main); bottomToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // handle action bar item clicks int itemId = item.getItemId(); // if statement is used because this sample is used elsewhere as a Library module if (itemId == R.id.action_def_exp) { // check the state of the menu item if (!applyActive) { applyDefinitionExpression(); // change the text to reset applyActive = true; item.setTitle(R.string.action_reset); } else { resetDefinitionExpression(); // change the text to apply applyActive = false; item.setTitle(R.string.action_def_exp); } } return true; } }); }
Example 14
Source File: MoviesFragment.java From cathode with Apache License 2.0 | 4 votes |
@Override public void createMenu(Toolbar toolbar) { super.createMenu(toolbar); toolbar.inflateMenu(R.menu.fragment_movies); }
Example 15
Source File: DisplayUtils.java From Mysplash with GNU Lesser General Public License v3.0 | 4 votes |
public static void inflateToolbarMenu(Toolbar toolbar, @MenuRes int menuId, Toolbar.OnMenuItemClickListener listener) { toolbar.inflateMenu(menuId); toolbar.setOnMenuItemClickListener(listener); // setOverflowMenuIconsVisible(toolbar.getMenu()); }
Example 16
Source File: ShowsFragment.java From cathode with Apache License 2.0 | 4 votes |
@Override public void createMenu(Toolbar toolbar) { super.createMenu(toolbar); toolbar.inflateMenu(R.menu.fragment_shows); }
Example 17
Source File: DashboardFragment.java From cathode with Apache License 2.0 | 4 votes |
@Override public void createMenu(Toolbar toolbar) { super.createMenu(toolbar); toolbar.inflateMenu(R.menu.search); }
Example 18
Source File: NowPlayingFragment.java From Jockey with Apache License 2.0 | 4 votes |
private void setupToolbar(Toolbar toolbar) { if (getResources().getConfiguration().orientation != ORIENTATION_LANDSCAPE) { toolbar.setBackground(new ColorDrawable(Color.TRANSPARENT)); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { toolbar.setElevation(getResources().getDimension(R.dimen.header_elevation)); } toolbar.setTitle(""); toolbar.setNavigationIcon(R.drawable.ic_clear_24dp); toolbar.inflateMenu(R.menu.activity_now_playing); toolbar.setOnMenuItemClickListener(this); toolbar.setNavigationOnClickListener(v -> { getActivity().onBackPressed(); }); mCreatePlaylistMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_save); mAppendToPlaylistMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_append); mShuffleMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_shuffle); mRepeatMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_repeat); toolbar.getMenu().findItem(R.id.menu_open_equalizer) .setEnabled(EqualizerActivity.newIntent(getContext(), false) != null); mPlayerController.getQueue() .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .map(this::queueContainsLocalSongs) .subscribe(this::updatePlaylistActionEnabled, throwable -> { Timber.e(throwable, "Failed to update playlist enabled state"); }); mPlayerController.isShuffleEnabled() .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .subscribe(this::updateShuffleIcon, throwable -> { Timber.e(throwable, "Failed to update shuffle icon"); }); mPlayerController.getRepeatMode() .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .subscribe(this::updateRepeatIcon, throwable -> { Timber.e(throwable, "Failed to update repeat icon"); }); }
Example 19
Source File: ShowSuggestionsFragment.java From cathode with Apache License 2.0 | 4 votes |
@Override public void createMenu(Toolbar toolbar) { super.createMenu(toolbar); toolbar.inflateMenu(R.menu.fragment_shows); toolbar.inflateMenu(R.menu.fragment_shows_recommended); }
Example 20
Source File: MovieSuggestionsFragment.java From cathode with Apache License 2.0 | 4 votes |
@Override public void createMenu(Toolbar toolbar) { super.createMenu(toolbar); toolbar.inflateMenu(R.menu.fragment_movies); toolbar.inflateMenu(R.menu.fragment_movies_recommended); }