Created
February 29, 2016 06:59
-
-
Save unclechen/985e8791c3da3c673ce3 to your computer and use it in GitHub Desktop.
动态设置圆角矩形背景,可以给TextView或者ViewGroup绘制圆角矩形背景,并设置颜色
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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