Java Code Examples for android.support.v7.widget.Toolbar#getChildCount()
The following examples show how to use
android.support.v7.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 Moment with GNU General Public License v3.0 | 6 votes |
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; } } } }
Example 2
Source File: CalligraphyFactory.java From Calligraphy with Apache License 2.0 | 6 votes |
/** * Will forcibly set text on the views then remove ones that didn't have copy. * * @param view toolbar view. */ private void applyFontToToolbar(final Toolbar view) { final CharSequence previousTitle = view.getTitle(); final CharSequence previousSubtitle = view.getSubtitle(); // The toolbar inflates both the title and the subtitle views lazily but luckily they do it // synchronously when you set a title and a subtitle programmatically. // So we set a title and a subtitle to something, then get the views, then revert. view.setTitle("uk.co.chrisjenx.calligraphy:toolbar_title"); view.setSubtitle("uk.co.chrisjenx.calligraphy:toolbar_subtitle"); // Iterate through the children to run post inflation on them final int childCount = view.getChildCount(); for (int i = 0; i < childCount; i++) { onViewCreated(view.getChildAt(i), view.getContext(), null); } // Remove views from view if they didn't have copy set. view.setTitle(previousTitle); view.setSubtitle(previousSubtitle); }
Example 3
Source File: TransitionUtil.java From android-transition with Apache License 2.0 | 6 votes |
/** * Search for a particular menu * * @param toolbar * @param menuId * @return the corresponding MenuItem, or null if not found */ public static MenuItem getMenuItem(@NonNull Toolbar toolbar, @IdRes int menuId) { View v; int childCount; View innerView; MenuItem menuItem; for (int i = 0; i < toolbar.getChildCount(); i++) { v = toolbar.getChildAt(i); if (v instanceof ActionMenuView) { childCount = ((ActionMenuView) v).getChildCount(); for (int j = 0; j < childCount; j++) { innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { menuItem = ((ActionMenuItemView) innerView).getItemData(); if (menuItem.getItemId() == menuId) { return menuItem; } } } } } return null; }
Example 4
Source File: TransitionUtil.java From android-transition with Apache License 2.0 | 6 votes |
/** * Get the list of visible MenuItems * * @param toolbar * @return the list of visible MenuItems */ public static List<MenuItem> getVisibleMenuItemList(@NonNull Toolbar toolbar) { List<MenuItem> list = new ArrayList<>(); for (int i = 0; i < toolbar.getChildCount(); i++) { final View v = toolbar.getChildAt(i); if (v instanceof ActionMenuView) { int childCount = ((ActionMenuView) v).getChildCount(); for (int j = 0; j < childCount; j++) { final View innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { list.add(((ActionMenuItemView) innerView).getItemData()); } } } } return list; }
Example 5
Source File: TypefaceHelper.java From android with MIT License | 6 votes |
public static Toolbar setTitle(Context context, Toolbar toolbar, CharSequence title) { if (toolbar == null) { return null; } toolbar.setTitle(title); try { final Typeface typeface = getTypeface(context, BOLD); final int childCount = toolbar.getChildCount(); for (int i = 0; i < childCount; i++) { final View v = toolbar.getChildAt(i); if (v instanceof TextView) { ((TextView) v).setTypeface(typeface); } } } catch (Exception e) { e.printStackTrace(); } return toolbar; }
Example 6
Source File: Util.java From Camera-Roll-Android-App with Apache License 2.0 | 6 votes |
@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_medium); textView.setTypeface(typeface); return textView; } } } return null; }
Example 7
Source File: HomeActivity.java From MangoBloggerAndroidApp with Mozilla Public License 2.0 | 5 votes |
/** * Get toolbar's navigation icon view reference. * * @param toolbar the main {@link Toolbar}. * @return a {@link ImageButton} reference. */ @Nullable private ImageButton getNavButtonView(Toolbar toolbar) { for (int i = 0; i < toolbar.getChildCount(); i++) if(toolbar.getChildAt(i) instanceof ImageButton) return (ImageButton) toolbar.getChildAt(i); return null; }
Example 8
Source File: MergedAppBarLayoutBehavior.java From react-native-bottom-sheet-behavior with MIT License | 5 votes |
private View findTitleTextView(Toolbar toolbar){ for (int i = 0; i < toolbar.getChildCount(); i++) { View toolBarChild = toolbar.getChildAt(i); if (toolBarChild instanceof TextView || toolBarChild instanceof ReactViewGroup) { return toolBarChild; } } return null; }
Example 9
Source File: Utils.java From IPTVFree with Apache License 2.0 | 5 votes |
/** * Get hamburger icon on navigation drawer * @param toolbar Toolbar * @return View */ private static View getNavButtonInToolBar(Toolbar toolbar) { for (int i = 0;i<toolbar.getChildCount();i++) { if(toolbar.getChildAt(i) instanceof ImageButton){ ImageButton button = (ImageButton) toolbar.getChildAt(i); if(button.getDrawable().getClass().getSuperclass().equals(DrawerArrowDrawable.class)) return toolbar.getChildAt(i); } } return null; }
Example 10
Source File: BaseActivity.java From Zom-Android-XMPP with GNU General Public License v3.0 | 5 votes |
public void applyStyleForToolbar() { final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); int themeColorHeader = settings.getInt("themeColor",-1); int themeColorText = settings.getInt("themeColorText",-1); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); //first set font Typeface typeface = CustomTypefaceManager.getCurrentTypeface(this); if (typeface != null) { for (int i = 0; i < toolbar.getChildCount(); i++) { View view = toolbar.getChildAt(i); if (view instanceof TextView) { TextView tv = (TextView) view; tv.setTypeface(typeface); break; } } } if (themeColorHeader != -1) { toolbar.setBackgroundColor(themeColorHeader); toolbar.setTitleTextColor(themeColorText); } }
Example 11
Source File: ActorToolbar.java From actor-platform with GNU Affero General Public License v3.0 | 5 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(Toolbar toolbarView, int toolbarIconsColor, Activity activity) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.SRC_IN); for (int i = 0; i < toolbarView.getChildCount(); i++) { final View v = toolbarView.getChildAt(i); doColorizing(v, colorFilter, toolbarIconsColor); } //Step 3: Changing the color of title and subtitle. toolbarView.setTitleTextColor(toolbarIconsColor); toolbarView.setSubtitleTextColor(toolbarIconsColor); }
Example 12
Source File: CommonFunctions.java From Expert-Android-Programming with MIT License | 5 votes |
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); } } }
Example 13
Source File: MainWindow.java From FancyPlaces with GNU General Public License v3.0 | 5 votes |
@Override public boolean onPrepareOptionsMenu(Menu menu) { menu.clear(); getMenuInflater().inflate(curState.curMenu, menu); Toolbar toolbar = (Toolbar) findViewById(R.id.main_window_toolbar); if (curState.curMenu == R.menu.menu_main_window_multi_select) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setTitle(getString(R.string.main_multi_selection_title)); toolbar.setBackgroundColor(getResources().getColor(R.color.ColorPrimaryDark)); int noOfChild = toolbar.getChildCount(); View view; // animate toolbar elements for (int i = 1; i < noOfChild; i++) { view = toolbar.getChildAt(i); view.setAlpha(0); view.setScaleY(0); view.setPivotY((float) 0.5 * view.getHeight()); view.animate().setDuration(200).scaleY(1).alpha(1); } } else if (curState.curMenu == R.menu.menu_main_window) { getSupportActionBar().setDisplayHomeAsUpEnabled(false); setDefaultTitle(); toolbar.setBackgroundColor(getResources().getColor(R.color.ColorPrimary)); } return super.onPrepareOptionsMenu(menu); }
Example 14
Source File: MusicUtils.java From Rey-MusicPlayer with Apache License 2.0 | 5 votes |
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; } } } }
Example 15
Source File: CustomToolbar.java From Lucid-Browser with Apache License 2.0 | 5 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 */ public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.SRC_IN); for(int i = 0; i < toolbarView.getChildCount(); i++) { final View v = toolbarView.getChildAt(i); doColorizing(v, colorFilter, toolbarIconsColor); } //Step 3: Changing the color of title and subtitle. toolbarView.setTitleTextColor(toolbarIconsColor); toolbarView.setSubtitleTextColor(toolbarIconsColor); }
Example 16
Source File: ActivityMain.java From fingen with Apache License 2.0 | 5 votes |
private ImageButton getNavButtonView(Toolbar toolbar) { for (int i = 0; i < toolbar.getChildCount(); i++) if (toolbar.getChildAt(i) instanceof ImageButton) return (ImageButton) toolbar.getChildAt(i); return null; }
Example 17
Source File: ToolbarColorizeHelper.java From RetroMusicPlayer with GNU General Public License v3.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(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); } }
Example 18
Source File: ToolbarColorizeHelper.java From IdeaTrackerPlus with MIT License | 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(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); } }
Example 19
Source File: ToolbarColorizeHelper.java From Slide with GNU General Public License v3.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(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); } }