效果图:
代码:
一、xml方式
代码: shape_rec_blue.xml
圆角矩形边框
圆角矩形背景
使用
二、kotlin方式
代码
圆角矩形边框
private fun getRoundRectStroke() = GradientDrawable().also {
it.shape = GradientDrawable.RECTANGLE
it.cornerRadius = 10f //圆角度数
val strokeWidth = 4 // 边框宽度
val strokeColor = Color.parseColor("#418DF9") //边框颜色
it.setStroke(strokeWidth, strokeColor)
}
圆角矩形背景
private fun getRoundRect() = GradientDrawable().also {
it.shape = GradientDrawable.RECTANGLE
it.cornerRadius = 10f
it.setColor(Color.parseColor("#418DF9"))
}
使用方法
view.background = getRoundRect()
完整源代码
https://gitee.com/hspbc/shapeDemos.git
|