本文整理汇总了Java中android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setCompoundDrawablesRelativeWithIntrinsicBounds方法的具体用法?Java TextView.setCompoundDrawablesRelativeWithIntrinsicBounds怎么用?Java TextView.setCompoundDrawablesRelativeWithIntrinsicBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setCompoundDrawablesRelativeWithIntrinsicBounds方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCompoundDrawablesRelativeWithIntrinsicBounds
import android.widget.TextView; //导入方法依赖的package包/类
/**
* @see android.widget.TextView#setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable,
* Drawable, Drawable, Drawable)
*/
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(TextView textView,
Drawable start, Drawable top, Drawable end, Drawable bottom) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) {
// Work around the platform bug described in setCompoundDrawablesRelative() above.
boolean isRtl = isLayoutRtl(textView);
textView.setCompoundDrawablesWithIntrinsicBounds(isRtl ? end : start, top,
isRtl ? start : end, bottom);
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
}
}
示例2: initTab
import android.widget.TextView; //导入方法依赖的package包/类
private void initTab() {
TextView firstView = (TextView) LayoutInflater.from(this).inflate(R.layout.bottom_tab_item, null);
firstView.setText(mTabResources[0][0]);
firstView.setTextColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary));
firstView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, Integer.valueOf(mTabResources[0][1]), 0, 0);
firstView.getCompoundDrawables()[1].setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
mTabLayout.getTabAt(0).setCustomView(firstView);
for (int i = 1; i < 3; i++) {
TextView textView = (TextView) LayoutInflater.from(this).inflate(R.layout.bottom_tab_item, null);
textView.setText(mTabResources[i][0]);
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, Integer.valueOf(mTabResources[i][1]), 0, 0);
mTabLayout.getTabAt(i).setCustomView(textView);
}
}
示例3: getView
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTextSize(18);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(images.get(position), 0, 0, 0);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0);
}
textView.setCompoundDrawablePadding(
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getContext().getResources().getDisplayMetrics()));
return view;
}
示例4: NavigationItem
import android.widget.TextView; //导入方法依赖的package包/类
public NavigationItem(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationItem,
defStyleAttr, defStyleRes);
String labelText = typedArray.getString(R.styleable.NavigationItem_labelText);
String infoText = typedArray.getString(R.styleable.NavigationItem_infoText);
Drawable logoDrawable = typedArray.getDrawable(R.styleable.NavigationItem_itemLogo);
@ColorRes int colorRes = typedArray.getResourceId(R.styleable.NavigationItem_imageColor, 0);
String launchingActivityName = typedArray.getString(R.styleable.NavigationItem_destinationActivityName);
int imageColor = ContextCompat.getColor(getContext(), colorRes);
typedArray.recycle();
View rootView = LayoutInflater.from(context).inflate(R.layout.navigation_item, this);
TextView buttonLabel = rootView.findViewById(R.id.buttonLabel);
buttonLabel.setText(labelText);
if (logoDrawable != null) {
Drawable mutatedLogoDrawable = logoDrawable.mutate();
mutatedLogoDrawable.setColorFilter(imageColor, PorterDuff.Mode.SRC_IN);
buttonLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(mutatedLogoDrawable, null,
null, null);
}
InfoButton infoButton = rootView.findViewById(R.id.infoButton);
infoButton.setInfoText(infoText);
infoButton.setColorFilter(imageColor);
CardView outerView = rootView.findViewById(R.id.cardView);
outerView.setOnClickListener((view) -> {
if (launchingActivityName != null) {
Intent intent = new Intent();
intent.setClassName(getContext().getPackageName(), launchingActivityName);
context.startActivity(intent);
} else {
Log.w(TAG, "Launching Activity name not set.");
}
});
}
示例5: makeItem
import android.widget.TextView; //导入方法依赖的package包/类
private static TextView makeItem(Context context, ItemInfo info) {
TextView textView = new TextView(context);
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(info.leftIcoResId == -1 ? null :
context.getResources().getDrawable(info.leftIcoResId), null,
info.rightIcoResId == -1 ? null : context.getResources().getDrawable(info.rightIcoResId), null);
textView.setText(info.itemText);
textView.setTextColor(info.textColor);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, info.textSize);
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setCompoundDrawablePadding((int) dpToPx(context, 8));
textView.setPadding(0, 0, (int) dpToPx(context, 8), 0);
textView.setOnClickListener(info.clickListener);
textView.setBackgroundResource(info.backgroundResId);
return textView;
}
示例6: initMainLeftViews
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 初始化主视图左边部分
*
* @param context
*/
private void initMainLeftViews(Context context) {
LayoutParams leftInnerParams = new LayoutParams(WRAP_CONTENT, MATCH_PARENT);
leftInnerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
leftInnerParams.addRule(RelativeLayout.CENTER_VERTICAL);
if (leftType == TYPE_LEFT_TEXTVIEW) {
// 初始化左边TextView
tvLeft = new TextView(context);
tvLeft.setId(ViewFinder.generateViewId());
tvLeft.setText(leftText);
tvLeft.setTextColor(leftTextColor);
tvLeft.setTextSize(TypedValue.COMPLEX_UNIT_PX, leftTextSize);
tvLeft.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
tvLeft.setSingleLine(true);
tvLeft.setOnClickListener(this);
// 设置DrawableLeft及DrawablePadding
if (leftDrawable != 0) {
tvLeft.setCompoundDrawablePadding((int) leftDrawablePadding);
if (SysUtils.hasJellyBeanMr1()) {
tvLeft.setCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, 0, 0, 0);
} else {
tvLeft.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, 0, 0, 0);
}
tvLeft.setPadding(0, 0, PADDING_5, 0);
} else {
tvLeft.setPadding(PADDING_5, 0, PADDING_5, 0);
}
rlMain.addView(tvLeft, leftInnerParams);
mFadeViewList.add(tvLeft);
} else if (leftType == TYPE_LEFT_IMAGEBUTTON) {
// 初始化左边ImageButton
btnLeft = new ImageButton(context);
btnLeft.setId(ViewFinder.generateViewId());
btnLeft.setBackgroundColor(Color.TRANSPARENT);
btnLeft.setImageResource(leftImageResource);
btnLeft.setPadding(PADDING_12, 0, PADDING_12, 0);
btnLeft.setOnClickListener(this);
rlMain.addView(btnLeft, leftInnerParams);
mFadeViewList.add(btnLeft);
} else if (leftType == TYPE_LEFT_CUSTOM_VIEW) {
// 初始化自定义View
viewCustomLeft = LayoutInflater.from(context).inflate(leftCustomViewRes, null);
if (viewCustomLeft.getId() == 0) {
viewCustomLeft.setId(ViewFinder.generateViewId());
}
rlMain.addView(viewCustomLeft, leftInnerParams);
mFadeViewList.add(viewCustomLeft);
}
}
示例7: setCompoundDrawablesRelativeWithIntrinsicBounds
import android.widget.TextView; //导入方法依赖的package包/类
public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) {
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(start, top, end, bottom);
}
示例8: bind
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Binds the {@code textView} with the specified {@code contact}.
*
* @param contact The contact.
* @param textView The TextView.
*/
public static void bind(Contact contact, TextView textView) {
textView.setText(contact.getName());
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(contact.getIcon(), 0, 0, 0);
}