android.support.v7.widget.Toolbar.getChildAt()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中android.support.v7.widget.Toolbar.getChildAt()方法的一些代码示例,展示了Toolbar.getChildAt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolbar.getChildAt()方法的具体详情如下:
包路径:android.support.v7.widget.Toolbar
类名称:Toolbar
方法名:getChildAt

Toolbar.getChildAt介绍

暂无

代码示例

代码示例来源:origin: rey5137/material

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());
    }
  }
}

代码示例来源:origin: rey5137/material

private ActionMenuView getMenuView(){
  if(mMenuView == null){
    for (int i = 0; i < mToolbar.getChildCount(); i++) {
      View child = mToolbar.getChildAt(i);
      if (child instanceof ActionMenuView) {
        mMenuView = (ActionMenuView) child;
        break;
      }
    }
  }
  return mMenuView;
}

代码示例来源:origin: chrisjenx/Calligraphy

/**
   * 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);
  }
}

代码示例来源:origin: xinghongfei/LookLook

private void animateToolbar() {
  // this is gross but toolbar doesn't expose it's children to animate them :(
  View t = toolbar.getChildAt(0);
  if (t != null && t instanceof TextView) {
    TextView title = (TextView) t;
    // fade in and space out the title.  Animating the letterSpacing performs horribly so
    // fake it by setting the desired letterSpacing then animating the scaleX ¯\_(ツ)_/¯
    title.setAlpha(0f);
    title.setScaleX(0.8f);
    title.animate()
        .alpha(1f)
        .scaleX(1f)
        .setStartDelay(500)
        .setDuration(900)
        .setInterpolator(AnimUtils.getFastOutSlowInInterpolator(this)).start();
  }
  View amv = toolbar.getChildAt(1);
  if (amv != null & amv instanceof ActionMenuView) {
    ActionMenuView actions = (ActionMenuView) amv;
    popAnim(actions.getChildAt(0), 500, 200); // filter
    popAnim(actions.getChildAt(1), 700, 200); // overflow
  }
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

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);
  }
  builder.setIcon(R.drawable.ic_more_vert)
      .show();
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

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);
  }
  tapTargetPromptBuilder.show();
}

代码示例来源:origin: henrichg/PhoneProfilesPlus

@Override
public View getChildAt(int position) {
 return toolbar.getChildAt(position);
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

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);
  }
  tapTargetPromptBuilder.show();
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

public void showSideNavigationPrompt(View view)
{
  final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this)
      .setPrimaryText(R.string.menu_prompt_title)
      .setSecondaryText(R.string.menu_prompt_description)
      .setFocalPadding(R.dimen.dp40)
      .setAnimationInterpolator(new FastOutSlowInInterpolator())
      .setMaxTextWidth(R.dimen.tap_target_menu_max_width)
      .setIcon(R.drawable.ic_menu);
  final Toolbar tb = this.findViewById(R.id.toolbar);
  tapTargetPromptBuilder.setTarget(tb.getChildAt(1));
  tapTargetPromptBuilder.setPromptStateChangeListener(new MaterialTapTargetPrompt.PromptStateChangeListener()
  {
    @Override
    public void onPromptStateChanged(@NonNull MaterialTapTargetPrompt prompt, int state)
    {
      if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED)
      {
        //Do something such as storing a value so that this prompt is never shown again
      }
    }
  });
  tapTargetPromptBuilder.show();
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

public void showSideNavigationPrompt(View view)
{
  final MaterialTapTargetPrompt.Builder tapTargetPromptBuilder = new MaterialTapTargetPrompt.Builder(this)
      .setPrimaryText(R.string.menu_prompt_title)
      .setSecondaryText(R.string.menu_prompt_description)
      .setAnimationInterpolator(new FastOutSlowInInterpolator())
      .setMaxTextWidth(R.dimen.tap_target_menu_max_width)
      .setIcon(R.drawable.ic_back)
      .setClipToView(findViewById(R.id.dialog_view));
  final Toolbar tb = this.findViewById(R.id.toolbar);
  tapTargetPromptBuilder.setTarget(tb.getChildAt(1));
  tapTargetPromptBuilder.setPromptStateChangeListener(new MaterialTapTargetPrompt.PromptStateChangeListener()
  {
    @Override
    public void onPromptStateChanged(@NonNull MaterialTapTargetPrompt prompt, int state)
    {
      if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED)
      {
        //Do something such as storing a value so that this prompt is never shown again
      }
    }
  });
  tapTargetPromptBuilder.show();
}

代码示例来源:origin: rumboalla/apkupdater

private void changeToolbar(
  String title,
  boolean arrow
) {
  try {
  ActionBar bar = getSupportActionBar();
    if (bar != null) {
      AnimationUtil.startToolbarAnimation(this, mToolbar);
      // This is to try to avoid the text to be cut during animation. TODO: Find a better way.
      TextView t = (TextView) mToolbar.getChildAt(0);
      t.getLayoutParams().width = 2000;
      bar.setTitle(title);
      bar.setDisplayHomeAsUpEnabled(arrow);
    }
  } catch (Exception e) {}
}

代码示例来源:origin: kollerlukas/Camera-Roll-Android-App

@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;
}

代码示例来源:origin: filestack/filestack-android

@SuppressLint("RestrictedApi")
  private void tintToolbar(Toolbar toolbar, @ColorInt int color) {
    Drawable drawable = DrawableCompat.wrap(toolbar.getOverflowIcon());
    DrawableCompat.setTint(drawable.mutate(), color);
    toolbar.setOverflowIcon(drawable);

    for (int i = 0; i < toolbar.getChildCount(); i++) {
      View child = toolbar.getChildAt(i);
      if (child instanceof AppCompatImageButton) {
        ((AppCompatImageButton) child).setSupportImageTintList(ColorStateList.valueOf(color));
      }
    }
  }
}

代码示例来源:origin: kollerlukas/Camera-Roll-Android-App

View v = toolbar.getChildAt(i);
if (v instanceof TextView) {
  titleView = (TextView) v;

代码示例来源:origin: powerpoint45/Lucid-Browser

/**
 * 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);
}

代码示例来源:origin: garretyoder/app-theme-engine

final View v = toolbar.getChildAt(i);

代码示例来源:origin: Mike-bel/MDStudySamples

final View v = toolbarView.getChildAt(i);

代码示例来源:origin: IdeaTrackerPlus/IdeaTrackerPlus

final View v = toolbarView.getChildAt(i);

代码示例来源:origin: jahirfiquitiva/IconShowcase

final View v = toolbar.getChildAt(i);

代码示例来源:origin: IdeaTrackerPlus/IdeaTrackerPlus

private void rightDrawerGuide() {
  new PreferencesManager(this).reset("right_drawer");
  new MyMaterialIntroView.Builder(MainActivity.this)
      .enableIcon(true)
      .enableFadeAnimation(true)
      .setFocusGravity(FocusGravity.CENTER)
      .setFocusType(Focus.NORMAL)
      .setInfoText(getString(R.string.right_drawer_guide))
      .setInfoTextSize(13)
      .performClick(true)
      .setTarget(mToolbar.getChildAt(2))
      .setListener(new MaterialIntroListener() {
        @Override
        public void onUserClicked(String MyMaterialIntroViewId) {
          rightDrawer.openDrawer();
        }
      })
      .setUsageId("right_drawer") //THIS SHOULD BE UNIQUE ID
      .show();
  mTinyDB.putBoolean(getString(R.string.right_drawer_pref), false);
}

相关文章

Toolbar类方法