本文整理了Java中android.widget.TextView.setBackgroundDrawable()
方法的一些代码示例,展示了TextView.setBackgroundDrawable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.setBackgroundDrawable()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:setBackgroundDrawable
暂无
代码示例来源:origin: aa112901/remusic
@Override
public void setBackgroundDrawable(Drawable background) {
super.setBackgroundDrawable(background);
if (mBackgroundHelper != null) {
mBackgroundHelper.setBackgroundDrawableExternal(background);
}
}
代码示例来源:origin: stackoverflow.com
TextView tv = (TextView)findViewById(R.id.image_test);
LayerDrawable ld = (LayerDrawable)tv.getBackground();
int topInset = tv.getHeight() / 2 ; //does not work!
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
代码示例来源:origin: lygttpod/SuperTextView
/**
* 设置textView的背景,用户传入drawable实现圆角之类的样式
*
* @param textView
* @param background
*/
private void setDefaultBackground(TextView textView, Drawable background) {
if (background != null) {
textView.setVisibility(VISIBLE);
if (Build.VERSION.SDK_INT < 16) {
textView.setBackgroundDrawable(background);
} else {
textView.setBackground(background);
}
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
/**
* 设置图片
*
* @param drawable
*/
public void setImage(Drawable drawable) {
if (drawable == null) {
throw new IllegalArgumentException("drawable cannot be null.");
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mGood.setBackground(drawable);
} else {
mGood.setBackgroundDrawable(drawable);
}
mGood.setText("");
setWidth(drawable.getIntrinsicWidth());
setHeight(mDistance + drawable.getIntrinsicHeight());
}
代码示例来源:origin: H07000223/FlycoDialog_Master
@Override
public void setUiBeforShow() {
super.setUiBeforShow();
/**set background color and corner radius */
float radius = dp2px(mCornerRadius);
mLlContainer.setBackgroundDrawable(CornerUtils.cornerDrawable(mBgColor, radius));
mTvBtnLeft.setBackgroundDrawable(CornerUtils.btnSelector(radius, mBgColor, mBtnPressColor, -2));
mTvBtnRight.setBackgroundDrawable(CornerUtils.btnSelector(radius, mBgColor, mBtnPressColor, -2));
mTvBtnMiddle.setBackgroundDrawable(CornerUtils.btnSelector(radius, mBgColor, mBtnPressColor, -2));
}
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
/**
* 设置文本
*
* @param text
*/
public void setText(String text) {
if (TextUtils.isEmpty(text)) {
throw new IllegalArgumentException("text cannot be null.");
}
mText = text;
mGood.setText(text);
mGood.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
int w = (int) mGood.getPaint().measureText(text);
setWidth(w);
setHeight(mDistance + getTextViewHeight(mGood, w));
}
代码示例来源:origin: WVector/AppUpdate
/**
* 默认空心 设置TextView 主题,
*
* @param textView textView
* @param strokeWidth 边框宽度 px
* @param cornerRadius 圆角
* @param color 颜色
*/
public static void setTextStrokeTheme(TextView textView, int strokeWidth, int cornerRadius, int color) {
textView.setBackgroundDrawable(getStrokeSolidDrawable(cornerRadius, strokeWidth, color, Color.WHITE));
textView.setTextColor(getColorStateList(Color.WHITE, color));
textView.getPaint().setFlags(Paint.FAKE_BOLD_TEXT_FLAG);
}
代码示例来源:origin: WVector/AppUpdate
/**
* 默认实心 设置TextView 主题,
*
* @param textView textView
* @param strokeWidth 边框宽度 px
* @param cornerRadius 圆角
* @param color 颜色
*/
public static void setTextSolidTheme(TextView textView, int strokeWidth, int cornerRadius, int color) {
textView.setBackgroundDrawable(getSolidStrokeDrawable(cornerRadius, strokeWidth, Color.WHITE, color));
textView.setTextColor(getColorStateList(color, Color.WHITE));
textView.getPaint().setFlags(Paint.FAKE_BOLD_TEXT_FLAG);
}
代码示例来源:origin: bingoogolapple/BGABanner-Android
mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
} else {
mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);
代码示例来源:origin: stackoverflow.com
public void onCreate() {
setContentView(R.layout.main);
final TextView tv = (TextView)findViewById(R.id.image_test);
final LayerDrawable ld = (LayerDrawable)tv.getBackground();
final ViewTreeObserver obs = mTv.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw () {
Log.d(TAG, "onPreDraw tv height is " + tv.getHeight()); // bad for performance, remove on production
int height = tv.getHeight();
int topInset = height / 2;
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
return true;
}
});
}
代码示例来源:origin: ZieIony/Carbon
@Override
public void setBackgroundDrawable(Drawable background) {
if (background instanceof RippleDrawable) {
setRippleDrawable((RippleDrawable) background);
return;
}
if (rippleDrawable != null && rippleDrawable.getStyle() == RippleDrawable.Style.Background) {
rippleDrawable.setCallback(null);
rippleDrawable = null;
}
super.setBackgroundDrawable(background);
updateBackgroundTint();
}
代码示例来源:origin: stackoverflow.com
private int mLastTvHeight = 0;
public void onCreate() {
setContentView(R.layout.main);
final TextView tv = (TextView)findViewById(R.id.image_test);
final LayerDrawable ld = (LayerDrawable)tv.getBackground();
final ViewTreeObserver obs = mTv.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw () {
Log.d(TAG, "onPreDraw tv height is " + tv.getHeight()); // bad for performance, remove on production
int height = tv.getHeight();
if (height != mLastTvHeight) {
mLastTvHeight = height;
int topInset = height / 2;
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
}
return true;
}
});
}
代码示例来源:origin: aurelhubert/ahbottomnavigation
notification.setBackground(drawable);
} else {
notification.setBackgroundDrawable(notificationBackgroundDrawable);
currentBackgroundColor, forceTint));
} else {
notification.setBackgroundDrawable(AHHelper.getTintDrawable(defautlDrawable,
currentBackgroundColor, forceTint));
代码示例来源:origin: H07000223/FlycoDialog_Master
mTvTitle.setBackgroundDrawable(CornerUtils.cornerDrawable(mTitleBgColor, new float[]{radius, radius, radius,
radius, 0, 0, 0, 0}));
mTvTitle.setText(mTitle);
mTvCancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mCancelTextSize);
mTvCancel.setTextColor(mCancelTextColor);
mTvCancel.setBackgroundDrawable(CornerUtils.listItemSelector(radius, mLvBgColor, mItemPressColor, 1, 0));
代码示例来源:origin: H07000223/FlycoDialog_Master
mTvTitle.setBackgroundDrawable(CornerUtils.cornerDrawable(mTitleBgColor, new float[]{radius, radius, radius,
radius, 0, 0, 0, 0}));
mTvTitle.setText(mTitle);
代码示例来源:origin: seven332/EhViewer
ll.addView(tgName);
tgName.setText(readableTagName != null ? readableTagName : tg.groupName);
tgName.setBackgroundDrawable(new RoundSideRectDrawable(colorName));
tag.setBackgroundDrawable(new RoundSideRectDrawable(colorTag));
tag.setTag(R.id.tag, tg.groupName + ":" + tagStr);
tag.setOnClickListener(this);
代码示例来源:origin: H07000223/FlycoDialog_Master
mTvBtnLeft.setBackgroundDrawable(CornerUtils.btnSelector(radius, mBgColor, mBtnPressColor, 0));
mTvBtnRight.setBackgroundDrawable(CornerUtils.btnSelector(radius, mBgColor, mBtnPressColor, 1));
mTvBtnMiddle.setBackgroundDrawable(CornerUtils.btnSelector(mBtnNum == 1 ? radius : 0, mBgColor, mBtnPressColor, -1));
代码示例来源:origin: ZieIony/Carbon
@Override
public void setRippleDrawable(RippleDrawable newRipple) {
if (rippleDrawable != null) {
rippleDrawable.setCallback(null);
if (rippleDrawable.getStyle() == RippleDrawable.Style.Background)
super.setBackgroundDrawable(rippleDrawable.getBackground());
}
if (newRipple != null) {
newRipple.setCallback(this);
newRipple.setBounds(0, 0, getWidth(), getHeight());
newRipple.setState(getDrawableState());
((Drawable) newRipple).setVisible(getVisibility() == VISIBLE, false);
if (newRipple.getStyle() == RippleDrawable.Style.Background)
super.setBackgroundDrawable((Drawable) newRipple);
}
rippleDrawable = newRipple;
}
代码示例来源:origin: stackoverflow.com
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.some_layout_name);
TextView t1 = (TextView) findViewById(R.id.text1);
TextView t2 = (TextView) findViewById(R.id.text2);
t1.setBackgroundColor(Color.GREEN);
t2.setBackgroundDrawable(t1.getBackground());
}
代码示例来源:origin: stackoverflow.com
TextView view = new TextView(this);
view.setText("click me");
view.setTextColor(0xffcccccc);
view.setGravity(Gravity.CENTER);
view.setTextSize(48);
final PathDrawable d = new PathDrawable();
view.setBackgroundDrawable(d);
OnClickListener l = new OnClickListener() {
@Override
public void onClick(View v) {
d.startAnimating();
}
};
view.setOnClickListener(l);
setContentView(view);
内容来源于网络,如有侵权,请联系作者删除!