android.widget.TextView#getCompoundDrawables ( )源码实例Demo

下面列出了android.widget.TextView#getCompoundDrawables ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Simpler   文件: StatusDataSetter.java
@Override
public void onDestroySuccess(long sid, long aid, TextView tvAttitude) {
    AttitudeContainer.sHeartContainer.remove(sid);
    Drawable[] compoundDrawables = tvAttitude.getCompoundDrawables();
    if (compoundDrawables[0] != null) {
        Drawable drawable = mActivity.getResources().getDrawable(R.drawable.ic_like);
        // 必须设置图片大小,否则不显示
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvAttitude.setCompoundDrawables(drawable, null, null, null);
    } else {
        tvAttitude.setTextColor(ContextCompat.getColor(mActivity, R.color.retweeted_count_text_color));
    }
    String countStr = tvAttitude.getText().toString();
    if (TextUtils.isDigitsOnly(countStr)) {
        int count = Integer.parseInt(countStr) - 1;
        tvAttitude.setText(NumberFormatter.formatWBCount(count, 60000));
    }
}
 
源代码2 项目: json2view   文件: DynamicHelper.java
/**
 * apply compound property in textView
 * position 0:left, 1:top, 2:right, 3:bottom
 * - REF : drawable to load as compoundDrawable
 * - BASE64 : decode as base64 and set as CompoundDrawable
 */
public static void applyCompoundDrawable(View view, DynamicProperty property, int position) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        Drawable[] d = textView.getCompoundDrawables();
        switch (property.type) {
            case REF: {
                try {
                    d[position] = view.getContext().getResources().getDrawable(getDrawableId(view.getContext(), property.getValueString()));
                } catch (Exception e) {}
            }
            break;
            case BASE64: {
                d[position] = property.getValueBitmapDrawable();
            }
            break;
            case DRAWABLE: {
                d[position] = property.getValueGradientDrawable();
            }
            break;
        }
        textView.setCompoundDrawablesWithIntrinsicBounds(d[0], d[1], d[2], d[3]);
    }
}
 
源代码3 项目: PainlessMusicPlayer   文件: BindingAdapters.java
@BindingAdapter({"drawableTop", "tintAttr"})
public static void setDrawableTopTintedFromAttr(
        @NonNull final TextView textView,
        @Nullable Drawable top,
        @AttrRes final int tintAttr) {
    final Drawable[] drawables = textView.getCompoundDrawables();
    if (top != null) {
        top = DrawableUtils.getTintedDrawableFromAttrTint(textView.getContext(), top, tintAttr);
    }
    textView.setCompoundDrawablesWithIntrinsicBounds(
            drawables[0],
            top,
            drawables[2],
            drawables[3]);
}
 
源代码4 项目: Newslly   文件: SNavigationDrawer.java
private void setTextViewDrawableColor(TextView textView, int color) {
    for (Drawable drawable : textView.getCompoundDrawables()) {
        if (drawable != null) {
            drawable.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(textView.getContext(), color), PorterDuff.Mode.SRC_IN));
        }
    }
}
 
private Drawable getStartCompoundDrawable(TextView textView) {
    Drawable[] drawables = textView.getCompoundDrawables();
    // Start drawable can be in the left or right index based on if the layout is rtl.
    if (drawables[0] != null) {
        return drawables[0];
    }
    return drawables[2];
}
 
源代码6 项目: UETool   文件: Util.java
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;
}
 
源代码7 项目: friendspell   文件: ViewUtil.java
public static void setDrawable(TextView textView, Drawable drawable, int position) {
  Drawable[] drawables = textView.getCompoundDrawables();
  textView.setCompoundDrawablesWithIntrinsicBounds(
      (position == 0) ? drawable : drawables[0],
      (position == 1) ? drawable : drawables[1],
      (position == 2) ? drawable : drawables[2],
      (position == 3) ? drawable : drawables[3]);
}
 
源代码8 项目: NoHttp   文件: ResCompat.java
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);
}
 
源代码9 项目: AndroidBase   文件: DrawableProvider.java
/**
 * 将radiobutton的drawable动态的缩放
 *
 * @param percent
 * @param rb
 * @return
 */
public static Drawable getScaleDrawableForRadioButton(float percent, TextView rb) {
    Drawable[] compoundDrawables = rb.getCompoundDrawables();
    Drawable drawable = null;
    for (Drawable d : compoundDrawables) {
        if (d != null) {
            drawable = d;
        }
    }
    drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f));
    return drawable;
}
 
/**
 * @param keyword
 */
public RightDrawableOnTouchListener(TextView view) {
    super();
    final Drawable[] drawables = view.getCompoundDrawables();
    if (drawables != null && drawables.length == 4)
        this.drawable = drawables[2];
}
 
源代码11 项目: NoHttp   文件: ResCompat.java
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);
}
 
源代码12 项目: Trebuchet   文件: Workspace.java
/**
 * 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;
}
 
源代码13 项目: TSnackBar   文件: TSnackbar.java
public TSnackbar setIconRight(@DrawableRes int drawableRes, float sizeDp) {
    final TextView tv = mView.getMessageView();
    Drawable drawable = ContextCompat.getDrawable(mContext, drawableRes);
    if (drawable != null) {
        drawable = fitDrawable(drawable, (int) convertDpToPixel(sizeDp, mContext));
    } else {
        throw new IllegalArgumentException("resource_id is not a valid drawable!");
    }
    final Drawable[] compoundDrawables = tv.getCompoundDrawables();
    tv.setCompoundDrawables(compoundDrawables[0], compoundDrawables[1], drawable, compoundDrawables[3]);
    return this;
}
 
private void setIcon(TextView view, String path) {
    Drawable icon = Drawable.createFromPath(path);
    Drawable checkbox = view.getCompoundDrawables()[2];

    if (icon != null)
        icon.setBounds(0, 0, checkbox.getIntrinsicWidth(), checkbox.getIntrinsicHeight());

    view.setCompoundDrawables(icon, null, checkbox, null);
}
 
源代码15 项目: NoHttp   文件: ResCompat.java
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);
}
 
源代码16 项目: DropDownMenu   文件: FixedTabIndicator.java
private void switchTab(int pos) {
    TextView tv = getChildAtCurPos(pos);

    Drawable drawable = tv.getCompoundDrawables()[2];
    int level = drawable.getLevel();

    if (mOnItemClickListener != null) {
        mOnItemClickListener.onItemClick(tv, pos, level == 1);
    }

    if (mLastIndicatorPosition == pos) {
        // 点击同一个条目时
        tv.setTextColor(level == 0 ? mTabSelectedColor : mTabDefaultColor);
        drawable.setLevel(1 - level);

        return;
    }

    mCurrentIndicatorPosition = pos;
    resetPos(mLastIndicatorPosition);

    //highLightPos(pos);
    tv.setTextColor(mTabSelectedColor);
    tv.getCompoundDrawables()[2].setLevel(1);

    mLastIndicatorPosition = pos;
}
 
源代码17 项目: friendspell   文件: CustomMatchers.java
public static Matcher<View> withCompoundDrawable(final int position) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    @Override public void describeTo(Description description) {
      description.appendText(
          "has compound drawable resource at position " + position);
    }
    @Override public boolean matchesSafely(TextView textView) {
      Drawable drawables[] = textView.getCompoundDrawables();
      return (drawables[position] != null);
    }
  };
}
 
源代码18 项目: friendspell   文件: CustomMatchers.java
public static Matcher<View> withoutCompoundDrawable(final int position) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    @Override public void describeTo(Description description) {
      description.appendText(
          "does not have compound drawable at position " + position);
    }
    @Override public boolean matchesSafely(TextView textView) {
      Drawable drawables[] = textView.getCompoundDrawables();
      return (drawables[position] == null);
    }
  };
}
 
源代码19 项目: MVPArms   文件: DrawableProvider.java
/**
 * 将 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);
}
 
源代码20 项目: LB-Launcher   文件: FolderIcon.java
private Drawable getTopDrawable(TextView v) {
    Drawable d = v.getCompoundDrawables()[1];
    return (d instanceof PreloadIconDrawable) ? ((PreloadIconDrawable) d).mIcon : d;
}
 
 方法所在类
 同类方法