ShapedBackground is an easy way to colour your backdrop as in Instagram stories
text.roundedBackground {
backgroundColor = getColor(R.color.serenade)
shadow {
dx = 5f
dy = 5f
radius = 10f
}
}
You can also add a gradient and set the background parameters
binding.text.roundedBackground {
gradient = arrayListOf(Color.MAGENTA,Color.CYAN)
cornerRadius = 40f
paddingVertical = 5f
paddingHorizontal = 5f
}
The ShapedBackground drawable uses View paddings to draw. You need to specify paddings to make the background drawable rendered without cropping:
android:padding="@dimen/your_padding"
In addition to TextView
, you can also use the ShapedBackground for EditText
RoundedBackgroundText(
value = text,
backgroundParams = BackgroundParams(
paddingHorizontal = 15.dp,
paddingVertical = 15.dp,
cornerRadius = 15.dp,
backgroundColor = Zeus,
shadow = ShadowParams(
dx = 2.dp,
dy = 2.dp,
radius = 1.dp
)
)
)
A gradient can be set instead of a solid background colour:
backgroundParams = BackgroundParams(
gradient = arrayListOf(Color.Black, Color.Blue)
)
- Add the repository
repositories {
...
maven { url 'https://jitpack.io' }
}
- Add the dependency:
Android View
implementation 'com.github.exyte.ShapedBackgroundAndroid:shapedbackground:1.1.1'
Jetpack Compose
implementation 'com.github.exyte.ShapedBackgroundAndroid:shapedbackgroundcompose:1.1.1'
Android View: Min SDK 17+
Jetpack Compose: Min SDK 21+