本文整理汇总了Java中android.graphics.drawable.ShapeDrawable.setAlpha方法的典型用法代码示例。如果您正苦于以下问题:Java ShapeDrawable.setAlpha方法的具体用法?Java ShapeDrawable.setAlpha怎么用?Java ShapeDrawable.setAlpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.ShapeDrawable
的用法示例。
在下文中一共展示了ShapeDrawable.setAlpha方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBadge
import android.graphics.drawable.ShapeDrawable; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
public void setBadge(String text) {
TextPaint textPaint = mTvBadge.getPaint();
float textWidth = textPaint.measureText(text);
Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
float textHeight = fontMetrics.bottom - fontMetrics.top;
int width = (int) Math.max(textWidth, textHeight);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mTvBadge.getLayoutParams();
params.width = width;
params.height = width;
mTvBadge.setLayoutParams(params);
mTvBadge.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
int radius = width / 2;
RoundRectShape shape = new RoundRectShape(new float[] {radius, radius, radius, radius, radius, radius, radius, radius}, null, null);
ShapeDrawable backgroundDrawable = new ShapeDrawable(shape);
backgroundDrawable.getPaint().setColor(Color.parseColor("#ff0000"));
backgroundDrawable.setAlpha(100);
mTvBadge.setBackground(backgroundDrawable);
mTvBadge.setText(text);
}