android.widget.TextView.getCompoundDrawables()方法的使用及代码示例

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

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

TextView.getCompoundDrawables介绍

暂无

代码示例

代码示例来源:origin: yanzhenjie/NoHttp

public static void setTopDrawable(TextView textView, Drawable topDrawable) {
  setDrawableBounds(topDrawable);
  Drawable left = textView.getCompoundDrawables()[0];
  Drawable right = textView.getCompoundDrawables()[2];
  Drawable bottom = textView.getCompoundDrawables()[3];
  textView.setCompoundDrawables(left, topDrawable, right, bottom);
}

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

Drawable[] drawables = v.getCompoundDrawables();
if (drawableStart != null)
  drawables[0] = drawableStart;

代码示例来源:origin: yanzhenjie/NoHttp

public static void setRightDrawable(TextView textView, Drawable rightDrawable) {
  setDrawableBounds(rightDrawable);
  Drawable left = textView.getCompoundDrawables()[0];
  Drawable top = textView.getCompoundDrawables()[1];
  Drawable bottom = textView.getCompoundDrawables()[3];
  textView.setCompoundDrawables(left, top, rightDrawable, bottom);
}

代码示例来源:origin: yanzhenjie/NoHttp

public static void setLeftDrawable(TextView textView, Drawable leftDrawable) {
  setDrawableBounds(leftDrawable);
  Drawable top = textView.getCompoundDrawables()[1];
  Drawable right = textView.getCompoundDrawables()[2];
  Drawable bottom = textView.getCompoundDrawables()[3];
  textView.setCompoundDrawables(leftDrawable, top, right, bottom);
}

代码示例来源:origin: yanzhenjie/NoHttp

public static void setBottomDrawable(TextView textView, Drawable bottomDrawable) {
  setDrawableBounds(bottomDrawable);
  Drawable left = textView.getCompoundDrawables()[0];
  Drawable top = textView.getCompoundDrawables()[1];
  Drawable right = textView.getCompoundDrawables()[2];
  textView.setCompoundDrawables(left, top, right, bottomDrawable);
}

代码示例来源:origin: JessYanCoding/MVPArms

/**
 * 将 TextView/RadioButton 中设置的 drawable 动态的缩放
 *
 * @param tv
 * @return
 */
public static Drawable getScaleDrawableForRadioButton2(float width, TextView tv) {
  Drawable[] compoundDrawables = tv.getCompoundDrawables();
  Drawable drawable = null;
  for (Drawable d : compoundDrawables) {
    if (d != null) {
      drawable = d;
    }
  }
  return getScaleDrawable2(width, drawable);
}

代码示例来源:origin: JessYanCoding/MVPArms

/**
 * 将 TextView/RadioButton 中设置的 drawable 动态的缩放
 *
 * @param percent
 * @param tv
 * @return
 */
public static Drawable getScaleDrawableForRadioButton(float percent, TextView tv) {
  Drawable[] compoundDrawables = tv.getCompoundDrawables();
  Drawable drawable = null;
  for (Drawable d : compoundDrawables) {
    if (d != null) {
      drawable = d;
    }
  }
  return getScaleDrawable(percent, drawable);
}

代码示例来源:origin: eleme/UETool

private static List<Pair<String, Bitmap>> getTextViewDrawableBitmap(TextView textView) {
  List<Pair<String, Bitmap>> bitmaps = new ArrayList<>();
  try {
    Drawable[] drawables = textView.getCompoundDrawables();
    bitmaps.add(new Pair<>("DrawableLeft", getDrawableBitmap(drawables[0])));
    bitmaps.add(new Pair<>("DrawableTop", getDrawableBitmap(drawables[1])));
    bitmaps.add(new Pair<>("DrawableRight", getDrawableBitmap(drawables[2])));
    bitmaps.add(new Pair<>("DrawableBottom", getDrawableBitmap(drawables[3])));
  } catch (Exception e) {
    e.printStackTrace();
  }
  return bitmaps;
}

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

@Test
public void testSetCompountDrawablesWithIntrinsicBounds_int_shouldNotCreateDrawablesForZero() throws Exception {
 textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
 assertNull(textView.getCompoundDrawables()[0]);
 assertNull(textView.getCompoundDrawables()[1]);
 assertNull(textView.getCompoundDrawables()[2]);
 assertNull(textView.getCompoundDrawables()[3]);
}

代码示例来源:origin: zhihu/Matisse

if (holder instanceof CaptureViewHolder) {
  CaptureViewHolder captureViewHolder = (CaptureViewHolder) holder;
  Drawable[] drawables = captureViewHolder.mHint.getCompoundDrawables();
  TypedArray ta = holder.itemView.getContext().getTheme().obtainStyledAttributes(
      new int[]{R.attr.capture_textColor});

代码示例来源:origin: aa112901/remusic

private Drawable applySupportCompoundDrawableTint(int position) {
  Drawable originDrawable = ((TextView) mView).getCompoundDrawables()[position];
  Drawable compoundDrawable = originDrawable;
  TintInfo tintInfo = mCompoundDrawableTintInfos[position];
  if (compoundDrawable != null && tintInfo != null && tintInfo.mHasTintList) {
    compoundDrawable = DrawableCompat.wrap(compoundDrawable);
    compoundDrawable.mutate();
    if (tintInfo.mHasTintList) {
      DrawableCompat.setTintList(compoundDrawable, tintInfo.mTintList);
    }
    if (tintInfo.mHasTintMode) {
      DrawableCompat.setTintMode(compoundDrawable, tintInfo.mTintMode);
    }
    if (compoundDrawable.isStateful()) {
      compoundDrawable.setState(originDrawable.getState());
    }
    return compoundDrawable;
  }
  return originDrawable;
}

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

@Test
public void testSetCompountDrawablesWithIntrinsicBounds_int_shouldCreateDrawablesWithResourceIds() throws Exception {
 textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.an_image, R.drawable.an_other_image, R.drawable.third_image, R.drawable.fourth_image);
 assertEquals(R.drawable.an_image, shadowOf(textView.getCompoundDrawables()[0]).getCreatedFromResId());
 assertEquals(R.drawable.an_other_image, shadowOf(textView.getCompoundDrawables()[1]).getCreatedFromResId());
 assertEquals(R.drawable.third_image, shadowOf(textView.getCompoundDrawables()[2]).getCreatedFromResId());
 assertEquals(R.drawable.fourth_image, shadowOf(textView.getCompoundDrawables()[3]).getCreatedFromResId());
}

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

@Test
public void testTextViewCompoundDrawablesAreSet() throws Exception {
 View mediaView = inflate(layout.main);
 TextView view = mediaView.findViewById(R.id.title);
 Drawable[] drawables = view.getCompoundDrawables();
 assertThat(shadowOf(drawables[0]).getCreatedFromResId()).isEqualTo(R.drawable.fourth_image);
 assertThat(shadowOf(drawables[1]).getCreatedFromResId()).isEqualTo(R.drawable.an_image);
 assertThat(shadowOf(drawables[2]).getCreatedFromResId()).isEqualTo(R.drawable.an_other_image);
 assertThat(shadowOf(drawables[3]).getCreatedFromResId()).isEqualTo(R.drawable.third_image);
}

代码示例来源:origin: hidroh/materialistic

assertEquals(R.drawable.ic_work_white_18dp,
    shadowOf(((TextView) activity.findViewById(R.id.posted))
        .getCompoundDrawables()[0]).getCreatedFromResId());
assertThat((TextView) activity.findViewById(R.id.source)).hasText("http://example.com");
reset(hackerNewsClient);

代码示例来源:origin: hidroh/materialistic

@Test
public void testPoll() {
  Intent intent = new Intent();
  intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
    @NonNull
    @Override
    public String getType() {
      return POLL_TYPE;
    }
    @Override
    public boolean isStoryType() {
      return true;
    }
    @Override
    public String getUrl() {
      return "http://example.com";
    }
  });
  controller = Robolectric.buildActivity(ItemActivity.class, intent);
  controller.create().start().resume();
  activity = controller.get();
  assertThat((View) activity.findViewById(R.id.source)).isNotVisible();
  assertEquals(R.drawable.ic_poll_white_18dp,
      shadowOf(((TextView) activity.findViewById(R.id.posted))
          .getCompoundDrawables()[0]).getCreatedFromResId());
}

代码示例来源:origin: chiuki/advanced-textview

private void changeAnimation(Operation operation) {
  Drawable[] drawables = textView.getCompoundDrawables();
  for (Drawable drawable : drawables) {
   if (drawable != null && drawable instanceof Animatable) {
    Animatable animatable = ((Animatable) drawable);
    switch (operation) {
     case START:
      animatable.start();
      break;
     case STOP:
      animatable.stop();
      break;
    }
   }
  }
 }
}

代码示例来源:origin: fookwood/Launcher3

/**
 * Returns the drawable for the given text view.
 */
public static Drawable getTextViewIcon(TextView tv) {
  final Drawable[] drawables = tv.getCompoundDrawables();
  for (int i = 0; i < drawables.length; i++) {
    if (drawables[i] != null) {
      return drawables[i];
    }
  }
  return null;
}

代码示例来源:origin: flipkart-incubator/proteus

@Override
 public void setDrawable(T view, Drawable drawable) {
  Drawable[] compoundDrawables = view.getCompoundDrawables();
  view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], drawable, compoundDrawables[3]);
 }
});

代码示例来源:origin: flipkart-incubator/proteus

@Override
 public void setDrawable(T view, Drawable drawable) {
  Drawable[] compoundDrawables = view.getCompoundDrawables();
  view.setCompoundDrawablesWithIntrinsicBounds(compoundDrawables[0], drawable, compoundDrawables[2], compoundDrawables[3]);
 }
});

代码示例来源:origin: flipkart-incubator/proteus

@Override
 public void setDrawable(T view, Drawable drawable) {
  Drawable[] compoundDrawables = view.getCompoundDrawables();
  view.setCompoundDrawablesWithIntrinsicBounds(drawable, compoundDrawables[1], compoundDrawables[2], compoundDrawables[3]);
 }
});

相关文章

TextView类方法