当前位置: 首页>>代码示例>>Java>>正文


Java Toolbar.getChildAt方法代码示例

本文整理汇总了Java中android.support.v7.widget.Toolbar.getChildAt方法的典型用法代码示例。如果您正苦于以下问题:Java Toolbar.getChildAt方法的具体用法?Java Toolbar.getChildAt怎么用?Java Toolbar.getChildAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.Toolbar的用法示例。


在下文中一共展示了Toolbar.getChildAt方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyFontsToTitle

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
private void applyFontsToTitle(Toolbar toolbar) {
    int childCount = toolbar.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = toolbar.getChildAt(i);
        if (child instanceof TextView) {
            TextView tv = (TextView) child;
            tv.setTextSize(getResources().getDimensionPixelSize(R.dimen.font_text_size));
            Typeface titleFont = Typeface.
                    createFromAsset(getAssets(), "fonts/AlexBrush-Regular.ttf");
            if (tv.getText().equals(toolbar.getTitle())) {
                tv.setTypeface(titleFont);
                break;
            }
        }
    }
}
 
开发者ID:Assassinss,项目名称:Moment,代码行数:17,代码来源:MainActivity.java

示例2: applyTypefaceToolbar

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
protected void applyTypefaceToolbar(Toolbar mToolbar, Typeface typeface) {
    if (mToolbar != null && typeface != null) {
        try {
            for(int i = 0; i < mToolbar.getChildCount(); i++){
                View view = mToolbar.getChildAt(i);
                if(view instanceof TextView){
                    TextView tv = (TextView) view;
                    if(tv.getText().equals(mToolbar.getTitle())){
                        tv.setTypeface(typeface);
                        //break;
                    }
                }
            }
        } catch (Exception ex) {
            // Stub
        }
    }
}
 
开发者ID:brunogabriel,项目名称:AndroidRealmNotes,代码行数:19,代码来源:BaseActivity.java

示例3: getNavigationMenuItem

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:26,代码来源:MainActivity.java

示例4: setToolbarTypeface

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@SuppressWarnings("inlineValue")
public static TextView setToolbarTypeface(Toolbar toolbar) {
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View view = toolbar.getChildAt(i);
        if (view instanceof TextView) {
            TextView textView = (TextView) view;
            if (textView.getText().equals(toolbar.getTitle())) {
                Typeface typeface = ResourcesCompat.getFont(toolbar.getContext(),
                        R.font.roboto_mono_regular);
                textView.setTypeface(typeface);
                return textView;
            }
        }
    }
    return null;
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:17,代码来源:Util.java

示例5: onCreate

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    TextView myTitle = (TextView) toolbar.getChildAt(0);
    Typeface tf = Typeface.createFromAsset(getAssets(),getResources().getString(R.string.font_name));
    myTitle.setTypeface(tf,Typeface.BOLD);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    AdView mAdView = (AdView)findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(getResources().getString(R.string.ad_device_test))
            .build();
    mAdView.loadAd(adRequest);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
    TabLayout tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
    tabLayout.setupWithViewPager(viewPager);
}
 
开发者ID:MuditSrivastava,项目名称:Canvas-Vision,代码行数:28,代码来源:MainActivity.java

示例6: colorizeToolbar

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);
    for(int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);
        if(v instanceof ImageButton) {
            ((ImageButton)v).getDrawable().setColorFilter(colorFilter);
        }
        if(v instanceof ActionMenuView) {
            for(int j = 0; j < ((ActionMenuView)v).getChildCount(); j++) {
                final View innerView = ((ActionMenuView)v).getChildAt(j);
                if(innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView)innerView).getCompoundDrawables().length;
                    for(int k = 0; k < drawablesCount; k++) {
                        if(((ActionMenuItemView)innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:garretyoder,项目名称:Cluttr,代码行数:29,代码来源:Util.java

示例7: applyFontForToolbarTitle

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
public static void applyFontForToolbarTitle(Activity context) {
    Toolbar toolbar = context.findViewById(R.id.toolbar);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        View view = toolbar.getChildAt(i);
        if (view instanceof TextView) {
            TextView tv = (TextView) view;

            if (tv.getText().equals(toolbar.getTitle())) {
                tv.setTypeface(TypefaceHelper.getTypeface(context, TypefaceHelper.FUTURA_BOLD));
                break;
            }
        }
    }
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:15,代码来源:MusicUtils.java

示例8: colorizeToolbar

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor) {
    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);
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Expert-Android-Programming,代码行数:15,代码来源:CommonFunctions.java

示例9: tintMenu

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, final @ColorInt int color) {
    try {
        final Field field = Toolbar.class.getDeclaredField("mCollapseIcon");
        field.setAccessible(true);
        Drawable collapseIcon = (Drawable) field.get(toolbar);
        if (collapseIcon != null) {
            field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // credits: https://snow.dog/blog/how-to-dynamicaly-change-android-toolbar-icons-color/
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    for (int i = 0; i < toolbar.getChildCount(); i++) {
        final View v = toolbar.getChildAt(i);
        // We can't iterate through the toolbar.getMenu() here, because we need the ActionMenuItemView. ATEActionMenuItemView is overriding the item icon tint color.
        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    int drawablesCount = ((ActionMenuItemView) innerView).getCompoundDrawables().length;
                    for (int k = 0; k < drawablesCount; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            ((ActionMenuItemView) innerView).getCompoundDrawables()[k].setColorFilter(colorFilter);
                        }
                    }
                }
            }
        }
    }

    if (menu == null)
        menu = toolbar.getMenu();
    if (menu != null && menu.size() > 0) {
        for (int i = 0; i < menu.size(); i++) {
            final MenuItem item = menu.getItem(i);
            // We must iterate through the toolbar.getMenu() too, to keep the tint when resuming the paused activity.
            if (item.getIcon() != null) {
                item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color));
            }
            // Search view theming
            if (item.getActionView() != null && (item.getActionView() instanceof android.widget.SearchView || item.getActionView() instanceof android.support.v7.widget.SearchView)) {
                SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color);
            }
        }
    }
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:50,代码来源:ToolbarProcessor.java

示例10: colorizeToolbar

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
 * 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(Toolbar toolbarView, int toolbarIconsColor, 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() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
开发者ID:IdeaTrackerPlus,项目名称:IdeaTrackerPlus,代码行数:54,代码来源:ToolbarColorizeHelper.java

示例11: colorizeToolbar

import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
 * 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(Toolbar toolbarView, int toolbarIconsColor, 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(() -> ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter));
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(ThemeStore.textColorPrimary(activity));
        toolbarView.setSubtitleTextColor(ThemeStore.textColorSecondary(activity));

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
开发者ID:h4h13,项目名称:RetroMusicPlayer,代码行数:49,代码来源:ToolbarColorizeHelper.java


注:本文中的android.support.v7.widget.Toolbar.getChildAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。