Java Code Examples for androidx.appcompat.widget.Toolbar#getChildAt()
The following examples show how to use
androidx.appcompat.widget.Toolbar#getChildAt() .
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: MainActivity.java From ChromeLikeTabSwitcher with Apache License 2.0 | 6 votes |
/** * Returns the menu item, which shows the navigation icon of the tab switcher's toolbar. * * @return The menu item, which shows the navigation icon of the tab switcher's toolbar, as an * instance of the class {@link View} or null, if no navigation icon is shown */ @Nullable private View getNavigationMenuItem() { Toolbar[] toolbars = tabSwitcher.getToolbars(); if (toolbars != null) { Toolbar toolbar = toolbars.length > 1 ? toolbars[1] : toolbars[0]; int size = toolbar.getChildCount(); for (int i = 0; i < size; i++) { View child = toolbar.getChildAt(i); if (child instanceof ImageButton) { return child; } } } return null; }
Example 2
Source File: MainActivity.java From MaterialTapTargetPrompt with Apache License 2.0 | 6 votes |
public void showOverflowPrompt(View view) { final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this) .setPrimaryText(R.string.overflow_prompt_title) .setSecondaryText(R.string.overflow_prompt_description) .setAnimationInterpolator(new FastOutSlowInInterpolator()) .setMaxTextWidth(R.dimen.tap_target_menu_max_width) .setIcon(R.drawable.ic_more_vert); final Toolbar tb = this.findViewById(R.id.toolbar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); tapTargetPromptBuilder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT).show(); } tapTargetPromptBuilder.show(); }
Example 3
Source File: MainActivity.java From MaterialTapTargetPrompt with Apache License 2.0 | 6 votes |
public void showStylePrompt(View view) { final MaterialTapTargetPrompt.Builder builder = new MaterialTapTargetPrompt.Builder(this, R.style.MaterialTapTargetPromptTheme_FabTarget); final Toolbar tb = this.findViewById(R.id.toolbar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); builder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT).show(); } builder.setIcon(R.drawable.ic_more_vert) .show(); }
Example 4
Source File: DialogStyleActivity.java From MaterialTapTargetPrompt with Apache License 2.0 | 6 votes |
public void showOverflowPrompt(View view) { final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this) .setPrimaryText(R.string.overflow_prompt_title) .setSecondaryText(R.string.overflow_prompt_description) .setAnimationInterpolator(new FastOutSlowInInterpolator()) .setMaxTextWidth(R.dimen.max_prompt_width) .setIcon(R.drawable.ic_more_vert) .setClipToView(findViewById(R.id.dialog_view)); final Toolbar tb = this.findViewById(R.id.toolbar); final View child = tb.getChildAt(2); if (child instanceof ActionMenuView) { final ActionMenuView actionMenuView = ((ActionMenuView) child); tapTargetPromptBuilder.setTarget(actionMenuView.getChildAt(actionMenuView.getChildCount() - 1)); } else { Toast.makeText(this, R.string.overflow_unavailable, Toast.LENGTH_SHORT).show(); } tapTargetPromptBuilder.show(); }
Example 5
Source File: WhatIfFragment.java From Easy_xkcd with Apache License 2.0 | 6 votes |
@Override protected void onPostExecute(Void dummy) { prefHelper.setNewestWhatif(mTitles.size()); setupAdapter(prefHelper.hideReadWhatIf()); Toolbar toolbar = ((MainActivity) getActivity()).getToolbar(); if (toolbar.getAlpha() == 0) { toolbar.setTranslationY(-300); toolbar.animate().setDuration(300).translationY(0).alpha(1); View view; for (int i = 0; i < toolbar.getChildCount(); i++) { view = toolbar.getChildAt(i); view.setTranslationY(-300); view.animate().setStartDelay(50 * (i + 1)).setDuration(70 * (i + 1)).translationY(0); } } if (newIntent) { Intent intent = new Intent(getActivity(), WhatIfActivity.class); startActivity(intent); newIntent = false; } }
Example 6
Source File: MergedAppBarLayoutBehavior.java From CustomBottomSheetBehavior with Apache License 2.0 | 5 votes |
private TextView findTitleTextView(Toolbar toolbar){ for (int i = 0; i < toolbar.getChildCount(); i++) { View toolBarChild = toolbar.getChildAt(i); if (toolBarChild instanceof TextView && ((TextView)toolBarChild).getText() != null && ((TextView)toolBarChild).getText().toString().contentEquals(mContext.getResources().getString(R.string.key_binding_default_toolbar_name))) { return (TextView) toolBarChild; } } return null; }
Example 7
Source File: OverviewBaseFragment.java From Easy_xkcd with Apache License 2.0 | 5 votes |
protected void animateToolbar() { Toolbar toolbar = ((MainActivity) getActivity()).getToolbar(); if (toolbar.getAlpha() == 0) { toolbar.setTranslationY(-300); toolbar.animate().setDuration(300).translationY(0).alpha(1); View view; for (int i = 2; i < toolbar.getChildCount(); i++) { view = toolbar.getChildAt(i); view.setTranslationY(-300); view.animate().setStartDelay(50 * (i + 1)).setDuration(70 * (i + 1)).translationY(0); } } }
Example 8
Source File: ComicFragment.java From Easy_xkcd with Apache License 2.0 | 5 votes |
protected void animateToolbar() { Toolbar toolbar = getMainActivity().getToolbar(); if (toolbar.getAlpha() == 0) { toolbar.setTranslationY(-300); toolbar.animate().setDuration(380).translationY(0).alpha(1); View view; for (int i = 0; i < toolbar.getChildCount(); i++) { view = toolbar.getChildAt(i); view.setTranslationY(-300); view.animate().setStartDelay(50 * (i + 1)).setDuration(70 * (i + 1)).translationY(0); } } }
Example 9
Source File: BaseFragmentActivity.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Sets the font of any TextView found within the ToolBar. * <br/> * TODO: Remove this function when this issue gets resolved: https://github.com/chrisjenx/Calligraphy/issues/295 */ private void setToolBarFont() { final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); for (int i = 0; i < toolbar.getChildCount(); i++) { final View child = toolbar.getChildAt(i); if (child instanceof TextView) { final TextView textView = (TextView) child; CalligraphyUtils.applyFontToTextView(textView, TypefaceUtils.load(getAssets(), "fonts/OpenSans-Semibold.ttf")); } } }
Example 10
Source File: ToolbarManager.java From material with Apache License 2.0 | 5 votes |
public ViewData(Toolbar toolbar){ int count = toolbar.getChildCount(); views = new ArrayList<>(count); lefts = new ArrayList<>(count); for(int i = 0; i < count; i++){ View child = toolbar.getChildAt(i); if(!(child instanceof ActionMenuView)) { views.add(child); lefts.add(child.getLeft()); } } }
Example 11
Source File: ToolbarColorizeHelper.java From arcusandroid with Apache License 2.0 | 4 votes |
/** * Use this method to colorize toolbar icons to the desired target color * * @param toolbarView toolbar view being colored * @param toolbarIconsColor the target color of toolbar icons * @param activity reference to activity needed to register observers */ public static void colorizeToolbar(@NonNull Toolbar toolbarView, int toolbarIconsColor, @NonNull Activity activity) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY); for (int i = 0; i < toolbarView.getChildCount(); i++) { final View v = toolbarView.getChildAt(i); //Step 1 : Changing the color of back button (or open drawer button). if (v instanceof ImageButton) { //Action Bar back button ((ImageButton) v).getDrawable().setColorFilter(colorFilter); } if (v instanceof ActionMenuView) { for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) { //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon. //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu final View innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) { if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) { final int finalK = k; //Important to set the color filter in seperate thread, by adding it to the message queue //Won't work otherwise. innerView.post(new Runnable() { @Override public void run() { Drawable drawable = ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK]; if (drawable != null) { drawable.setColorFilter(colorFilter); } } }); } } } } } //Step 3: Changing the color of title and subtitle. toolbarView.setTitleTextColor(toolbarIconsColor); toolbarView.setSubtitleTextColor(toolbarIconsColor); } }