本文整理匯總了Java中android.widget.TextView.setCompoundDrawables方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.setCompoundDrawables方法的具體用法?Java TextView.setCompoundDrawables怎麽用?Java TextView.setCompoundDrawables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setCompoundDrawables方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreateSuccess
import android.widget.TextView; //導入方法依賴的package包/類
@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));
}
}
示例2: showBigImg
import android.widget.TextView; //導入方法依賴的package包/類
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第一張
}
}
示例3: layoutPunctuationsAndReturnStartIndexOfMoreSuggestions
import android.widget.TextView; //導入方法依賴的package包/類
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;
}
示例4: convert
import android.widget.TextView; //導入方法依賴的package包/類
@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);
}
示例5: resetLayout
import android.widget.TextView; //導入方法依賴的package包/類
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);
}
}
示例6: setTextViewBottomImage
import android.widget.TextView; //導入方法依賴的package包/類
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;
}
示例7: setTitleTxt
import android.widget.TextView; //導入方法依賴的package包/類
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);
}
示例8: setCompoundIconLeftOrClear
import android.widget.TextView; //導入方法依賴的package包/類
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);
}
}
示例9: setLeftImage
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 設置左側圖片
* @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);
}
}
示例10: apply
import android.widget.TextView; //導入方法依賴的package包/類
@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]);
}
}
示例11: setBottomImage
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 設置底部圖片
* @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);
}
}
示例12: changeCompoundDrawableSize
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 修改 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]);
}
示例13: setDrawleft
import android.widget.TextView; //導入方法依賴的package包/類
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);
}
示例14: bind
import android.widget.TextView; //導入方法依賴的package包/類
@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);
}
示例15: setLeftDrawable
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 設置左邊的drawable
*
* @param tv
* @param drawable
*/
public static void setLeftDrawable(TextView tv, Drawable drawable) {
tv.setCompoundDrawables(drawable, null, null, null);
}