Java Code Examples for androidx.appcompat.widget.Toolbar#getChildCount()

The following examples show how to use androidx.appcompat.widget.Toolbar#getChildCount() . 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 vote down vote up
/**
 * 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: WhatIfFragment.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: MergedAppBarLayoutBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 5 votes vote down vote up
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 4
Source File: OverviewBaseFragment.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
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 5
Source File: ComicFragment.java    From Easy_xkcd with Apache License 2.0 5 votes vote down vote up
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 6
Source File: BaseFragmentActivity.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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 7
Source File: ToolbarManager.java    From material with Apache License 2.0 5 votes vote down vote up
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 8
Source File: ToolbarColorizeHelper.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}