Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/infotech-group/android-drawable-dsl
DSL for constructing the drawables in Kotlin instead of in XML
https://github.com/infotech-group/android-drawable-dsl
android drawable dsl kotlin
Last synced: 6 days ago
JSON representation
DSL for constructing the drawables in Kotlin instead of in XML
- Host: GitHub
- URL: https://github.com/infotech-group/android-drawable-dsl
- Owner: infotech-group
- License: apache-2.0
- Created: 2017-04-07T09:40:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-28T12:38:46.000Z (over 6 years ago)
- Last Synced: 2024-08-02T05:15:19.775Z (3 months ago)
- Topics: android, drawable, dsl, kotlin
- Language: Kotlin
- Size: 120 KB
- Stars: 179
- Watchers: 8
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-android - android-drawable-dsl - 通过 kotlin 构造 drawable 而不是 XML 的 DSL 🔥 (开源库 / DSL)
- awesome-kotlin-libraries-for-android - Android Drawable DSL - DSL for constructing the drawables in Kotlin instead of in XML. (<a name="utility"></a>Utility <sup>[Back ⇈](#contents)</sup>)
README
# Android Drawable Kotlin DSL [![CircleCI](https://circleci.com/gh/infotech-group/android-drawable-dsl.svg?style=svg)](https://circleci.com/gh/infotech-group/android-drawable-dsl)
DSL for constructing the drawables in Kotlin instead of in XML
## Examples
### Shape drawables
```xml
```
replace it with
```kotlin
shapeDrawable {
shape = GradientDrawable.OVALsolidColor = Color.parseColor("#199fff")
stroke {
width = dip(2)
color = Color.parseColor("#444444")
}
}
```### State selectors
```xml
```
replace it with
```kotlin
stateListDrawable {checkedState {
shapeDrawable {
solidColor = Color.BLACK
}
}pressedState {
shapeDrawable {
solidColor = Color.RED
}
}defaultState {
shapeDrawable {
solidColor = Color.WHITE
}
}
}
```### Layer drawables
```xml
```
replace it with
```kotlin
layerDrawable(shapeDrawable {
shape = GradientDrawable.OVALstroke {
width = ctx.dip(5)
color = Color.parseColor("#000000")
}
},shapeDrawable {
shape = GradientDrawable.OVALstroke {
width = ctx.dip(2)
color = Color.parseColor("#ffffff")
}
}
)
```### Install
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
```[![](https://jitpack.io/v/infotech-group/android-drawable-dsl.svg)](https://jitpack.io/#infotech-group/android-drawable-dsl)
```groovy
compile "com.github.infotech-group:android-drawable-dsl:0.3.0"
```### Contribute
We haven't covered 100% of the XML DSL, contributions are very welcome
Please write a [test](/src/androidTest) for every new tag you add, we (hopefully) made it easy to do