Skip to content

Instantly share code, notes, and snippets.

@unclechen
Created February 29, 2016 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unclechen/985e8791c3da3c673ce3 to your computer and use it in GitHub Desktop.
Save unclechen/985e8791c3da3c673ce3 to your computer and use it in GitHub Desktop.
动态设置圆角矩形背景,可以给TextView或者ViewGroup绘制圆角矩形背景,并设置颜色
//1. 先新建一个圆角矩形,并包装成一个ShapeDrawable
ShapeDrawable backgroundDrawable = new ShapeDrawable(new RoundRectShape(new float[] {10, 10, 10, 10, 10, 10, 10, 10},
null, null));
//2. 设置背景颜色
backgroundDrawable.getPaint().setColor(Color.parseColor("#1fbaf3"));
//3. 设置透明度
backgroundDrawable.setsetAlpha(100);
//4. 给需要用的ViewGroup/View设置背景
TextView.setBackgroundDrawable(backgroundDrawable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment