/** * 设置textView的drawable * * @param textView 对象 * @param drawableLeft 左边图标 * @param drawableTop 上边图标 * @param drawableRight 右边图标 * @param drawableBottom 下边图标 * @param drawablePadding 图标距离文字的间距 */ public void setDrawable(TextView textView, Drawable drawableLeft, Drawable drawableTop, Drawable drawableRight, Drawable drawableBottom, int drawablePadding) { textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, drawableTop, drawableRight, drawableBottom); textView.setCompoundDrawablePadding(drawablePadding); }
/** * 设置textView的drawable * * @param textView 对象 * @param drawableLeft 左边图标 * @param drawableRight 右边图标 * @param drawablePadding 图标距离文字的间距 */ public void setDefaultDrawable(TextView textView, Drawable drawableLeft, Drawable drawableRight, int drawablePadding, int drawableWidth, int drawableHeight) { if (drawableLeft != null || drawableRight != null) { textView.setVisibility(VISIBLE); } //可以指定drawable的宽高 if (drawableWidth != -1 && drawableHeight != -1) { if (drawableLeft != null) { drawableLeft.setBounds(0, 0, drawableWidth, drawableHeight); } if (drawableRight != null) { drawableRight.setBounds(0, 0, drawableWidth, drawableHeight); } textView.setCompoundDrawables(drawableLeft, null, drawableRight, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, drawableRight, null); } textView.setCompoundDrawablePadding(drawablePadding); }
textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0); textView.setCompoundDrawablePadding( (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getContext().getResources().getDisplayMetrics())); return view;
@Override public void onBindViewHolder(ViewHolder viewHolder, int position) { viewHolder.info = list.get(position); viewHolder.text.setText(viewHolder.info.loadLabel(getPackageManager())); // Setting tinted example icon Context context = ExamplesActivity.this; Drawable icon = DrawableCompat.wrap(viewHolder.info.loadIcon(getPackageManager())); DrawableCompat.setTint(icon, ContextCompat.getColor(context, R.color.primary)); int padding = getResources().getDimensionPixelSize(R.dimen.example_icon_padding); viewHolder.text.setCompoundDrawablePadding(padding); viewHolder.text.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); }
mTitle.setBackgroundColor(BLUE); mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN); mTitle.setCompoundDrawablePadding(MARGIN + PADDING); mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); mContent.addView(mTitle);
v.setCompoundDrawablePadding(a.getDimensionPixelSize(attr, 0));
Toast toast = Toast.makeText(this, "I am custom Toast!", Toast.LENGTH_LONG); View toastView = toast.getView(); //This'll return the default View of the Toast. /* And now you can get the TextView of the default View of the Toast. */ TextView toastMessage = (TextView) toastView.findViewById(android.R.id.message); toastMessage.setTextSize(25); toastMessage.setTextColor(Color.RED); toastMessage.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_fly, 0, 0, 0); toastMessage.setGravity(Gravity.CENTER); toastMessage.setCompoundDrawablePadding(16); toastView.setBackgroundColor(Color.CYAN); toast.show();
text.setPadding(18, 18, 18, 18); text.setTextColor(Color.WHITE); text.setCompoundDrawablePadding(20); text.setGravity(Gravity.CENTER_VERTICAL);
text.setPadding(18, 18, 18, 18); text.setTextColor(Color.WHITE); text.setCompoundDrawablePadding(20); text.setGravity(Gravity.CENTER_VERTICAL);
text.setPadding(14, 7, 7, 7); text.setTextColor(Color.BLACK); text.setCompoundDrawablePadding(10); text.setGravity(Gravity.CENTER_VERTICAL);
text.setPadding(14, 7, 7, 7); text.setTextColor(Color.BLACK); text.setCompoundDrawablePadding(10); text.setGravity(Gravity.CENTER_VERTICAL);
/** * Sets title and icon of provider */ private void setUpTitle() { requestWindowFeature(Window.FEATURE_NO_TITLE); mTitle = new TextView(getContext()); int res = getContext().getResources().getIdentifier(mProviderName.toString(), "drawable", getContext().getPackageName()); Drawable icon = getContext().getResources().getDrawable(res); String sb = mProviderName.toString().substring(0, 1).toUpperCase(Locale.getDefault()) + mProviderName.toString().substring(1, mProviderName.toString().length()); mTitle.setText(sb); mTitle.setGravity(Gravity.CENTER_VERTICAL); mTitle.setTextColor(Color.WHITE); mTitle.setTypeface(Typeface.DEFAULT_BOLD); mTitle.setBackgroundColor(BLUE); mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN); mTitle.setCompoundDrawablePadding(MARGIN + PADDING); mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); if (!titleStatus) mContent.addView(mTitle); }
/** * Sets title and icon of provider */ private void setUpTitle() { requestWindowFeature(Window.FEATURE_NO_TITLE); mTitle = new TextView(getContext()); int res = getContext().getResources().getIdentifier(mProviderName.toString(), "drawable", getContext().getPackageName()); Drawable icon = getContext().getResources().getDrawable(res); String sb = mProviderName.toString().substring(0, 1).toUpperCase(Locale.getDefault()) + mProviderName.toString().substring(1, mProviderName.toString().length()); mTitle.setText(sb); mTitle.setGravity(Gravity.CENTER_VERTICAL); mTitle.setTextColor(Color.WHITE); mTitle.setTypeface(Typeface.DEFAULT_BOLD); mTitle.setBackgroundColor(BLUE); mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN); mTitle.setCompoundDrawablePadding(MARGIN + PADDING); mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); if (!titleStatus) mContent.addView(mTitle); }
public static void setIconDrawable(Context mContext, TextView view, IIcon icon, int size, int padding) { view.setCompoundDrawablesWithIntrinsicBounds(new IconicsDrawable(mContext) .icon(icon) .color(Color.WHITE) .sizeDp(size), null, null, null); view.setCompoundDrawablePadding(ScreenUtil.dip2px(mContext, padding)); } }
private void setIconDrawable(TextView view, IIcon icon) { view.setCompoundDrawablesWithIntrinsicBounds(new IconicsDrawable(this) .icon(icon) .color(Color.WHITE) .sizeDp(16), null, null, null); view.setCompoundDrawablePadding(DimenUtils.dp2px(this, 10)); }
@Override public void setDimension(T view, float dimension) { view.setCompoundDrawablePadding((int) dimension); } });
private void setIconDrawable(TextView view, IIcon icon) { view.setCompoundDrawablesWithIntrinsicBounds(new IconicsDrawable(getActivity()) .icon(icon) .color(ThemeUtils.getThemeColor(getActivity(), R.attr.colorPrimary)) .sizeDp(14), null, null, null); view.setCompoundDrawablePadding(DimenUtils.dp2px(getActivity(), 5)); }
public static void setTextDrawableTop(TextView txt, int padDip, int resId) { txt.setCompoundDrawables(null, getTextDrawable(txt.getContext(), resId), null, null); if (padDip >= 0) { txt.setCompoundDrawablePadding(dp2Px(txt.getContext(), padDip)); } }
Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); TextView tv = (TextView) toast.getView().findViewById(android.R.id.message); if (null!=tv) { tv.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0); tv.setCompoundDrawablePadding(context.getResources().getDimensionPixelSize(R.dimen.padding_toast));