本文整理汇总了Java中android.support.v7.widget.Toolbar.getChildCount方法的典型用法代码示例。如果您正苦于以下问题:Java Toolbar.getChildCount方法的具体用法?Java Toolbar.getChildCount怎么用?Java Toolbar.getChildCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.Toolbar
的用法示例。
在下文中一共展示了Toolbar.getChildCount方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onGlobalLayout
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override public void onGlobalLayout() {
final Toolbar toolbar = mToolbarReference.get();
final Context context = mContextRef.get();
final CalligraphyFactory factory = mCalligraphyFactory.get();
if (toolbar == null) return;
if (factory == null || context == null) {
removeSelf(toolbar);
return;
}
int childCount = toolbar.getChildCount();
if (childCount != 0) {
// Process children, defer draw as it has set the typeface.
for (int i = 0; i < childCount; i++) {
factory.onViewCreated(toolbar.getChildAt(i), context, null);
}
}
removeSelf(toolbar);
toolbar.setSubtitle(originalSubTitle);
}
示例2: applyFontToToolbar
import android.support.v7.widget.Toolbar; //导入方法依赖的package包/类
/**
* Will forceably 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(" ");
view.setSubtitle(" ");
// 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);
}
示例3: 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;
}
}
}
}
示例4: 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
}
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
});
}
}
}
}
}
}
}
示例8: 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;
}
}
}
}
示例9: 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);
}
}
}
示例10: 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);
}
}
}
}
示例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(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);
}
}
示例12: 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);
}
}