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

The following are Jave code examples for showing how to use setCompoundDrawables() 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: HeadlineNews   File: NewsListAdapter.java   View Source Code Vote up 6 votes
private void showBigImg(BaseViewHolder helper, News item) {
    //中间大图布局,判断是否有视频
    TextView tvBottomRight = helper.getView(R.id.id_info_tv);
    if (item.has_video) {
        helper.setVisible(R.id.id_play_iv, true);//显示播放按钮
        tvBottomRight.setCompoundDrawables(null, null, null, null);//去除TextView左侧图标
        helper.setText(R.id.id_info_tv, item.video_duration + "");//设置时长
        GlideApp.with(mContext)
                .load(item.video_detail_info.detail_video_large_image.url)
                .into((ImageView) helper.getView(R.id.id_iv));
    } else {
        helper.setVisible(R.id.id_play_iv, false);//隐藏播放按钮
        tvBottomRight.setCompoundDrawables(ResouceUtil.getDrawable(R.drawable.icon_picture_group), null, null, null);//TextView增加左侧图标
        helper.setText(R.id.id_info_tv, item.gallary_image_count + " 图");//设置时长
        GlideApp.with(mContext).load(item.image_list.get(0).url.replace("list/300x196", "large")).centerCrop()
                .into((ImageView) helper.getView(R.id.id_iv));//中间图片使用image_list第一张
    }
}
 
Example 3
Project: AOSP-Kayboard-7.1.2   File: SuggestionStripLayoutHelper.java   View Source Code Vote up 6 votes
private int layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
        final PunctuationSuggestions punctuationSuggestions, final ViewGroup stripView) {
    final int countInStrip = Math.min(punctuationSuggestions.size(), PUNCTUATIONS_IN_STRIP);
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, mDividerViews.get(positionInStrip));
        }

        final TextView wordView = mWordViews.get(positionInStrip);
        final String punctuation = punctuationSuggestions.getLabel(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(positionInStrip);
        wordView.setText(punctuation);
        wordView.setContentDescription(punctuation);
        wordView.setTextScaleX(1.0f);
        wordView.setCompoundDrawables(null, null, null, null);
        wordView.setTextColor(mColorAutoCorrect);
        stripView.addView(wordView);
        setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
    }
    mMoreSuggestionsAvailable = (punctuationSuggestions.size() > countInStrip);
    return countInStrip;
}
 
Example 4
Project: TextReader   File: TocListAdapter.java   View Source Code Vote up 6 votes
@Override
public void convert(EasyLVHolder holder, int position, BookMixAToc.mixToc.Chapters chapters) {
    TextView tvTocItem = holder.getView(R.id.tvTocItem);
    tvTocItem.setText(chapters.title);
    Drawable drawable;
    if (currentChapter == position + 1) {
        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_red));
        drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_activated);
    } else if (isEpub || FileUtils.getChapterFile(bookId, position + 1).length() > 10) {
        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_black));
        drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_download);
    } else {
        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_black));
        drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_normal);
    }
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    tvTocItem.setCompoundDrawables(drawable, null, null, null);
}
 
Example 5
Project: BookReader-master   File: TocListAdapter.java   View Source Code Vote up 6 votes
@Override
public void convert(EasyLVHolder holder, int position, BookMixAToc.mixToc.Chapters chapters) {
    TextView tvTocItem = holder.getView(R.id.tvTocItem);
    tvTocItem.setText(chapters.title);
    Drawable drawable;
    if (currentChapter == position + 1) {
        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_red));
        drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_activated);
    } else if (isEpub || FileUtils.getChapterFile(bookId, position + 1).length() > 10) {
        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_black));
        drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_download);
    } else {
        tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_black));
        drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_normal);
    }
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    tvTocItem.setCompoundDrawables(drawable, null, null, null);
}
 
Example 6
Project: SimpleUILauncher   File: Hotseat.java   View Source Code Vote up 5 votes
void resetLayout() {
    mContent.removeAllViewsInLayout();

    // 在hotseat中显示进入所有应用列表的图标
    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
Example 7
Project: MedicationReminder   File: ViewHolder.java   View Source Code Vote up 5 votes
public ViewHolder setTextViewBottomImage(int viewId, Drawable resId)
{
    TextView view = getView(viewId);
    resId.setBounds(0, 0, resId.getMinimumWidth(), resId.getMinimumHeight());

     view.setCompoundDrawables(null,null,null,resId);
    return this;
}
 
Example 8
Project: NeiHanDuanZiTV   File: BoxingActivity.java   View Source Code Vote up 5 votes
private void setTitleTxt(BoxingConfig config) {
    TextView titleTxt = (TextView) findViewById(R.id.pick_album_txt);
    if (config.getMode() == BoxingConfig.Mode.VIDEO) {
        titleTxt.setText(R.string.boxing_video_title);
        titleTxt.setCompoundDrawables(null, null, null, null);
        return;
    }
    mPickerFragment.setTitleTxt(titleTxt);
}
 
Example 9
Project: RecyclerViewPreferences   File: Util.java   View Source Code Vote up 5 votes
public static void setCompoundIconLeftOrClear(TextView tv, IIcon icon, int size, int color) {
    if (icon == null) {
        tv.setCompoundDrawables(null, null, null, null);
    } else {
        tv.setCompoundDrawables(getCompoundIcon(icon, size, color), null, null, null);
    }
}
 
Example 10
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置左侧图片
 * @param textView
 * @param resId
 * @param padding
 */
public static void setLeftImage(TextView textView, int resId, float padding) {
    if (textView != null) {
        Drawable drawable = textView.getContext().getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(drawable, null, null, null);
    }
}
 
Example 11
Project: Android-Skin   File: DrawableLRTBAttr.java   View Source Code Vote up 5 votes
@Override
public void apply(View view) {
    if (view == null) {
        return;
    }
    if (view instanceof TextView) {//button extends TextView
        TextView textView = (TextView) view;
        Drawable bg = AndroidSkin.getInstance().getSkinDrawable(
                attrValueTypeName, attrValueRefName, attrValueRefId);
        Drawable[] bound = {null, null, null, null};
        switch (type) {
            case DRAWABLE_LEFT:
                bound[0] = bg;
                break;
            case DRAWABLE_TOP:
                bound[1] = bg;
                break;
            case DRAWABLE_RIGHT:
                bound[2] = bg;
                break;
            case DRAWABLE_BOTTOM:
                bound[3] = bg;
                break;
        }
        //textView.setCompoundDrawablePadding(0);
        textView.setCompoundDrawables(null, null, null, null);
        /// 这一步必须要做,否则不会显示.
        if (bound[0] != null)
            bound[0].setBounds(0, 0, bound[0].getIntrinsicWidth(), bound[0].getIntrinsicHeight());
        if (bound[1] != null)
            bound[1].setBounds(0, 0, bound[1].getIntrinsicWidth(), bound[1].getIntrinsicHeight());
        if (bound[2] != null)
            bound[2].setBounds(0, 0, bound[2].getIntrinsicWidth(), bound[2].getIntrinsicHeight());
        if (bound[3] != null)
            bound[3].setBounds(0, 0, bound[3].getIntrinsicWidth(), bound[3].getIntrinsicHeight());

        textView.setCompoundDrawables(bound[0], bound[1], bound[2], bound[3]);
    }

}
 
Example 12
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 设置底部图片
 * @param textView
 * @param drawable
 * @param padding
 */
public static void setBottomImage(TextView textView, Drawable drawable, float padding) {
    if (textView != null) {
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        }
        textView.setCompoundDrawablePadding(DensityUtils.dip2px(textView.getContext(), padding));
        textView.setCompoundDrawables(null, null, null, drawable);
    }
}
 
Example 13
Project: HeadlineNews   File: CompoundDrawableUtil.java   View Source Code Vote up 5 votes
/**
 * 修改 textview 的drawable size
 * <p>
 *
 * @param textView   textview
 * @param where      上下左右    0-左  1-上  2-右  3- 下
 * @param expectedWh 宽高,单位 dp
 *                   </p>
 * @see TextView#getCompoundDrawables()
 */
public static void changeCompoundDrawableSize(TextView textView, int where, int expectedWh) {
    if (where < 0 || where > 3)
        return;
    Drawable[] drawables = textView.getCompoundDrawables();
    Drawable drawable = drawables[where];
    if (drawable == null)
        return;
    int wh = SizeUtils.dp2px(expectedWh);
    Rect rect = new Rect(0, 0, wh, wh);
    drawable.setBounds(rect);
    drawables[where] = drawable;
    textView.setCompoundDrawables(drawables[0], drawables[1], drawables[2], drawables[3]);
}
 
Example 14
Project: CXJPadProject   File: UseMsgFragment.java   View Source Code Vote up 4 votes
public void setDrawleft(TextView view, int id) {
    if (!isAdded()) return;
    Drawable drawable_n = getResources().getDrawable(id);
    drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());  //此为必须写的
    view.setCompoundDrawables(drawable_n, null, null, null);
}
 
Example 15
Project: QMUI_Android   File: QMUITabSegment.java   View Source Code Vote up 4 votes
@Override
protected void bind(Tab item, TabItemView view, int position) {
    TextView tv = view.getTextView();
    setTextViewTypeface(tv, false);
    // custom view
    List<View> mCustomViews = item.getCustomViews();
    if (mCustomViews != null && mCustomViews.size() > 0) {
        view.setTag(R.id.qmui_view_can_not_cache_tag, true);
        for (View v : mCustomViews) {
            // 防止先 setCustomViews 然后再 updateTabText 时会重复添加 customView 导致 crash
            if (v.getParent() == null) {
                view.addView(v);
            }
        }
    }
    // gravity
    if (mMode == MODE_FIXED) {
        int gravity = item.getGravity();
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) tv.getLayoutParams();
        lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, (gravity & Gravity.LEFT) == Gravity.LEFT ? RelativeLayout.TRUE : 0);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL, (gravity & Gravity.CENTER) == Gravity.CENTER ? RelativeLayout.TRUE : 0);
        lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, (gravity & Gravity.RIGHT) == Gravity.RIGHT ? RelativeLayout.TRUE : 0);
        tv.setLayoutParams(lp);
    }

    tv.setText(item.getText());

    // icon
    if (item.getNormalIcon() == null) {
        tv.setCompoundDrawablePadding(0);
        tv.setCompoundDrawables(null, null, null, null);
    } else {
        Drawable drawable = item.getNormalIcon();
        if (drawable != null) {
            drawable = drawable.mutate();
            setDrawable(tv, drawable, getTabIconPosition(item));
            tv.setCompoundDrawablePadding(QMUIDisplayHelper.dp2px(getContext(), 4));
        } else {
            tv.setCompoundDrawables(null, null, null, null);
        }
    }
    int textSize = item.getTextSize();
    if (textSize == Tab.USE_TAB_SEGMENT) {
        textSize = mTabTextSize;
    }
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

    if (position == mSelectedIndex) {
        if (mIndicatorView != null && getViews().size() > 1) {
            if (mIndicatorDrawable != null) {
                QMUIViewHelper.setBackgroundKeepingPadding(mIndicatorView, mIndicatorDrawable);
            } else {
                mIndicatorView.setBackgroundColor(getTabSelectedColor(item));
            }
        }
        changeTabColor(view.getTextView(), getTabSelectedColor(item), item, STATUS_SELECTED);
    } else {
        changeTabColor(view.getTextView(), getTabNormalColor(item), item, STATUS_NORMAL);
    }

    view.setTag(position);
    view.setOnClickListener(mTabOnClickListener);
}
 
Example 16
Project: qmui   File: QMUITabSegment.java   View Source Code Vote up 4 votes
@Override
protected void bind(Tab item, TabItemView view, int position) {
    TextView tv = view.getTextView();
    setTextViewTypeface(tv, false);
    // custom view
    List<View> mCustomViews = item.getCustomViews();
    if (mCustomViews != null && mCustomViews.size() > 0) {
        view.setTag(R.id.qmui_view_can_not_cache_tag, true);
        for (View v : mCustomViews) {
            // 防止先 setCustomViews 然后再 updateTabText 时会重复添加 customView 导致 crash
            if (v.getParent() == null) {
                view.addView(v);
            }
        }
    }
    // gravity
    if (mMode == MODE_FIXED) {
        int gravity = item.getGravity();
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) tv.getLayoutParams();
        lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, (gravity & Gravity.LEFT) == Gravity.LEFT ? RelativeLayout.TRUE : 0);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL, (gravity & Gravity.CENTER) == Gravity.CENTER ? RelativeLayout.TRUE : 0);
        lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, (gravity & Gravity.RIGHT) == Gravity.RIGHT ? RelativeLayout.TRUE : 0);
        tv.setLayoutParams(lp);
    }

    tv.setText(item.getText());

    // icon
    if (item.getNormalIcon() == null) {
        tv.setCompoundDrawablePadding(0);
        tv.setCompoundDrawables(null, null, null, null);
    } else {
        Drawable drawable = item.getNormalIcon();
        if (drawable != null) {
            drawable = drawable.mutate();
            setDrawable(tv, drawable, getTabIconPosition(item));
            tv.setCompoundDrawablePadding(QMUIDisplayHelper.dp2px(getContext(), 4));
        } else {
            tv.setCompoundDrawables(null, null, null, null);
        }
    }
    int textSize = item.getTextSize();
    if (textSize == Tab.USE_TAB_SEGMENT) {
        textSize = mTabTextSize;
    }
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

    if (position == mSelectedIndex) {
        if (mIndicatorView != null && getViews().size() > 1) {
            if (mIndicatorDrawable != null) {
                QMUIViewHelper.setBackgroundKeepingPadding(mIndicatorView, mIndicatorDrawable);
            } else {
                mIndicatorView.setBackgroundColor(getTabSelectedColor(item));
            }
        }
        changeTabColor(view.getTextView(), getTabSelectedColor(item), item, STATUS_SELECTED);
    } else {
        changeTabColor(view.getTextView(), getTabNormalColor(item), item, STATUS_NORMAL);
    }

    view.setTag(position);
    view.setOnClickListener(mTabOnClickListener);
}
 
Example 17
Project: PicShow-zhaipin   File: DrawableProvider.java   View Source Code Vote up 2 votes
/**
 * 设置左边的drawable
 *
 * @param tv
 * @param drawable
 */
public static void setLeftDrawable(TextView tv, Drawable drawable) {
    tv.setCompoundDrawables(drawable, null, null, null);
}
 
Example 18
Project: yyox   File: DrawableProvider.java   View Source Code Vote up 2 votes
/**
 * 设置左边的drawable
 *
 * @param tv
 * @param drawable
 */
public static void setLeftDrawable(TextView tv, Drawable drawable) {
    tv.setCompoundDrawables(drawable, null, null, null);
}
 
Example 19
Project: MoligyMvpArms   File: DrawableProvider.java   View Source Code Vote up 2 votes
/**
 * 设置左边的drawable
 *
 * @param tv
 * @param drawable
 */
public static void setLeftDrawable(TextView tv, Drawable drawable) {
    tv.setCompoundDrawables(drawable, null, null, null);
}
 
Example 20
Project: Aurora   File: DrawableProvider.java   View Source Code Vote up 2 votes
/**
 * 设置左边的drawable
 *
 * @param tv
 * @param drawable
 */
public static void setLeftDrawable(TextView tv, Drawable drawable) {
    tv.setCompoundDrawables(drawable, null, null, null);
}