Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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.OVAL

solidColor = 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.OVAL

stroke {
width = ctx.dip(5)
color = Color.parseColor("#000000")
}
},

shapeDrawable {
shape = GradientDrawable.OVAL

stroke {
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