Java Code Examples for android.widget.TextView.getCompoundDrawables()

The following are Jave code examples for showing how to use getCompoundDrawables() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Simpler   File: StatusDataSetter.java   View Source Code Vote up 6 votes
@Override
public void onCreateSuccess(boolean lastHeart, long sid, long aid, TextView tvAttitude) {
    AttitudeContainer.sHeartContainer.put(sid, aid);
    if (lastHeart) {
        AppToast.showToast("上次点过赞了");
    } else {
        String countStr = tvAttitude.getText().toString();
        if (TextUtils.isDigitsOnly(countStr)) {
            int count = Integer.parseInt(countStr) + 1;
            tvAttitude.setText(NumberFormatter.formatWBCount(count, 60000));
        }
    }
    Drawable[] compoundDrawables = tvAttitude.getCompoundDrawables();
    if (compoundDrawables[0] != null) {
        Drawable drawable = mActivity.getResources().getDrawable(R.drawable.ic_like_press);
        // 必须设置图片大小,否则不显示
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvAttitude.setCompoundDrawables(drawable, null, null, null);
    } else {
        tvAttitude.setTextColor(ContextCompat.getColor(mActivity, R.color.colorPrimary));
    }
}
 
Example 2
Project: QMUI_Android   File: QMUITabSegment.java   View Source Code Vote up 6 votes
private void changeTabColor(TextView textView, int color, Tab model, int status, boolean preventColorChange) {
    if (!preventColorChange) {
        textView.setTextColor(color);
    }

    if (!model.isDynamicChangeIconColor()) {
        if (status == STATUS_NORMAL || model.getSelectedIcon() == null) {
            setDrawable(textView, model.getNormalIcon(), getTabIconPosition(model));
        } else if (status == STATUS_SELECTED) {
            setDrawable(textView, model.getSelectedIcon(), getTabIconPosition(model));
        }
        return;
    }

    if (!preventColorChange) {
        Drawable drawable = textView.getCompoundDrawables()[getTabIconPosition(model)];
        if (drawable == null) {
            return;
        }
        // 这里要拿textView已经set并mutate的drawable
        QMUIDrawableHelper.setDrawableTintColor(drawable, color);
        setDrawable(textView, model.getNormalIcon(), getTabIconPosition(model));
    }

}
 
Example 3
Project: Simpler   File: StatusDataSetter.java   View Source Code Vote up 6 votes
@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));
    }
}
 
Example 4
Project: mvparms   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将radiobutton的drawable动态的缩放
 *
 * @param rb
 * @return
 */
public static Drawable getScaleDrawableForRadioButton2(float width, TextView rb) {
    Drawable[] compoundDrawables = rb.getCompoundDrawables();
    Drawable drawable = null;
    for (Drawable d : compoundDrawables) {
        if (d != null) {
            drawable = d;
        }
    }
    float percent = width * 1.0f / drawable.getIntrinsicWidth();
    drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f));
    return drawable;
}
 
Example 5
Project: GitHub   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将radiobutton的drawable动态的缩放
 *
 * @param rb
 * @return
 */
public static Drawable getScaleDrawableForRadioButton2(float width, TextView rb) {
    Drawable[] compoundDrawables = rb.getCompoundDrawables();
    Drawable drawable = null;
    for (Drawable d : compoundDrawables) {
        if (d != null) {
            drawable = d;
        }
    }
    float percent = width * 1.0f / drawable.getIntrinsicWidth();
    drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f));
    return drawable;
}
 
Example 6
Project: FlickLauncher   File: Workspace.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 7
Project: LaunchEnr   File: Workspace.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 8
Project: NeiHanDuanZiTV   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将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;
}
 
Example 9
Project: NeiHanDuanZiTV   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将radiobutton的drawable动态的缩放
 *
 * @param rb
 * @return
 */
public static Drawable getScaleDrawableForRadioButton2(float width, TextView rb) {
    Drawable[] compoundDrawables = rb.getCompoundDrawables();
    Drawable drawable = null;
    for (Drawable d : compoundDrawables) {
        if (d != null) {
            drawable = d;
        }
    }
    float percent = width * 1.0f / drawable.getIntrinsicWidth();
    drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f));
    return drawable;
}
 
Example 10
Project: Musicoco   File: MySheetsController.java   View Source Code Vote up 5 votes
private void emptyViewThemeChange(int[] colors) {

        int accentC;
        if (colors == null) {
            ThemeEnum themeEnum = new AppPreference(activity).getTheme();
            int[] cs = ColorUtils.get10ThemeColors(activity, themeEnum);

            accentC = cs[2];

        } else {
            accentC = colors[0];
        }

        View v = mEmptyListNoticeContainer.getChildAt(EMPTY_VIEW_INDEX);
        TextView text = (TextView) v.findViewById(R.id.sheet_empty_add);

        text.setTextColor(accentC);
        Drawable[] drawables = text.getCompoundDrawables();
        for (Drawable d : drawables) {
            if (d != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    d.setTint(accentC);
                }
            }
        }

    }
 
Example 11
Project: MVPArmsTest1   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将radiobutton的drawable动态的缩放
 *
 * @param rb
 * @return
 */
public static Drawable getScaleDrawableForRadioButton2(float width, TextView rb) {
    Drawable[] compoundDrawables = rb.getCompoundDrawables();
    Drawable drawable = null;
    for (Drawable d : compoundDrawables) {
        if (d != null) {
            drawable = d;
        }
    }
    float percent = width * 1.0f / drawable.getIntrinsicWidth();
    drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * percent + 0.5f), (int) (drawable.getIntrinsicHeight() * percent + 0.5f));
    return drawable;
}
 
Example 12
Project: SimpleUILauncher   File: Workspace.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 13
Project: mvparms   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将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;
}
 
Example 14
Project: MoligyMvpArms   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将 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);
}
 
Example 15
Project: MoligyMvpArms   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将 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);
}
 
Example 16
Project: topsnackbar   File: RightDrawableOnTouchListener.java   View Source Code Vote up 5 votes
public RightDrawableOnTouchListener(TextView view, float sizeClick) {
    super();
    final Drawable[] drawables = view.getCompoundDrawables();
    context = view.getContext();
    this.sizeClick = sizeClick;
    if (drawables != null && drawables.length == 4)
        this.drawable = drawables[2];
}
 
Example 17
Project: Aurora   File: DrawableProvider.java   View Source Code Vote up 5 votes
/**
 * 将 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);
}
 
Example 18
Project: HeadlineNews   File: CompoundDrawableUtil.java   View Source Code Vote up 5 votes
public static void changeCompoundDrawableWithPadding(TextView textView, int where, int resId, int drawablePadding) {
    if (where < 0 || where > 3)
        return;
    if (resId <= 0) {
        LogUtils.e("changeCompoundDrawableWithPadding  resId = " + resId + " is error.....");
        return;
    }
    Drawable[] drawables = textView.getCompoundDrawables();
    Drawable exptectedDrawable = ResouceUtil.getDrawable(resId);
   
    drawables[where] = exptectedDrawable;
    textView.setCompoundDrawablePadding(SizeUtils.dp2px(drawablePadding));
    textView.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
}
 
Example 19
Project: Melophile   File: PresentationUtils.java   View Source Code Vote up 5 votes
public static void setDrawableColor(TextView view, int color){
    Drawable[] drawables=view.getCompoundDrawables();
    for(Drawable drawable:drawables){
        if(drawable!=null){
            drawable.mutate();
            DrawableCompat.setTint(drawable,color);
        }
    }
}
 
Example 20
Project: FlickLauncher   File: FolderIcon.java   View Source Code Vote up 4 votes
private Drawable getTopDrawable(TextView v) {
    Drawable d = v.getCompoundDrawables()[1];
    return (d instanceof PreloadIconDrawable) ? ((PreloadIconDrawable) d).mIcon : d;
}