{"id":13516287,"url":"https://github.com/infotech-group/android-drawable-dsl","last_synced_at":"2026-01-17T16:26:07.961Z","repository":{"id":81516014,"uuid":"87530414","full_name":"infotech-group/android-drawable-dsl","owner":"infotech-group","description":"DSL for constructing the drawables in Kotlin instead of in XML","archived":false,"fork":false,"pushed_at":"2018-05-28T12:38:46.000Z","size":123,"stargazers_count":180,"open_issues_count":2,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-01T20:36:20.804Z","etag":null,"topics":["android","drawable","dsl","kotlin"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infotech-group.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-04-07T09:40:41.000Z","updated_at":"2024-10-23T03:44:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"f7a60923-f147-4faf-b7c9-8c26c6758c17","html_url":"https://github.com/infotech-group/android-drawable-dsl","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infotech-group%2Fandroid-drawable-dsl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infotech-group%2Fandroid-drawable-dsl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infotech-group%2Fandroid-drawable-dsl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infotech-group%2Fandroid-drawable-dsl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infotech-group","download_url":"https://codeload.github.com/infotech-group/android-drawable-dsl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429459,"owners_count":20775805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","drawable","dsl","kotlin"],"created_at":"2024-08-01T05:01:21.061Z","updated_at":"2026-01-17T16:26:07.940Z","avatar_url":"https://github.com/infotech-group.png","language":"Kotlin","funding_links":[],"categories":["开源库","\u003ca name=\"utility\"\u003e\u003c/a\u003eUtility \u003csup\u003e[Back ⇈](#contents)\u003c/sup\u003e"],"sub_categories":["DSL"],"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)\n\nDSL for constructing the drawables in Kotlin instead of in XML\n\n## Examples\n\n### Shape drawables\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cshape xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:shape=\"oval\"\u003e\n    \u003csolid android:color=\"#199fff\" /\u003e\n    \u003cstroke\n        android:width=\"2dp\"\n        android:color=\"#444444\" /\u003e\n\u003c/shape\u003e\n```\n\nreplace it with\n\n```kotlin\nshapeDrawable {\n  shape = GradientDrawable.OVAL\n\n  solidColor = Color.parseColor(\"#199fff\")\n\n  stroke {\n    width = dip(2)\n    color = Color.parseColor(\"#444444\")\n  }\n}\n```\n\n### State selectors\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cselector xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n\n    \u003citem android:state_checked=\"true\"\u003e\n        \u003cshape\u003e\n            \u003csolid android:color=\"@android:color/black\" /\u003e\n        \u003c/shape\u003e\n    \u003c/item\u003e\n\n    \u003citem android:state_pressed=\"true\"\u003e\n        \u003cshape\u003e\n            \u003csolid android:color=\"@android:color/holo_red_dark\" /\u003e\n        \u003c/shape\u003e\n    \u003c/item\u003e\n\n    \u003citem\u003e\n        \u003cshape\u003e\n            \u003csolid android:color=\"@android:color/white\" /\u003e\n        \u003c/shape\u003e\n    \u003c/item\u003e\n\u003c/selector\u003e\n```\n\nreplace it with\n\n```kotlin\nstateListDrawable {\n\n  checkedState {\n    shapeDrawable {\n      solidColor = Color.BLACK\n    }\n  }\n\n  pressedState {\n    shapeDrawable {\n      solidColor = Color.RED\n    }\n  }\n\n  defaultState {\n    shapeDrawable {\n      solidColor = Color.WHITE\n    }\n  }\n}\n```\n\n### Layer drawables\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003clayer-list xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n\n    \u003citem\u003e\n        \u003cshape android:shape=\"oval\"\u003e\n            \u003cstroke\n                android:width=\"5dp\"\n                android:color=\"#000000\" /\u003e\n        \u003c/shape\u003e\n    \u003c/item\u003e\n\n    \u003citem\u003e\n        \u003cshape android:shape=\"oval\"\u003e\n            \u003cstroke\n                android:width=\"2dp\"\n                android:color=\"#ffffff\" /\u003e\n        \u003c/shape\u003e\n    \u003c/item\u003e\n\n\u003c/layer-list\u003e\n```\n\nreplace it with\n\n```kotlin\nlayerDrawable(\n\n    shapeDrawable {\n      shape = GradientDrawable.OVAL\n\n      stroke {\n        width = ctx.dip(5)\n        color = Color.parseColor(\"#000000\")\n      }\n    },\n\n    shapeDrawable {\n      shape = GradientDrawable.OVAL\n\n      stroke {\n        width = ctx.dip(2)\n        color = Color.parseColor(\"#ffffff\")\n      }\n    }\n)\n```\n\n### Install\n\n```groovy\nrepositories {\n    maven { url 'https://jitpack.io' }\n}\n```\n\n[![](https://jitpack.io/v/infotech-group/android-drawable-dsl.svg)](https://jitpack.io/#infotech-group/android-drawable-dsl)\n\u003ca href=\"http://www.methodscount.com/?lib=com.github.infotech-group%3Aandroid-drawable-dsl%3A0.3.0\"\u003e\u003cimg src=\"https://img.shields.io/badge/Methods and size-110 | 15 KB-e91e63.svg\"/\u003e\u003c/a\u003e\n\n```groovy\ncompile \"com.github.infotech-group:android-drawable-dsl:0.3.0\"\n```\n\n### Contribute\n\nWe haven't covered 100% of the XML DSL, contributions are very welcome\n\nPlease write a [test](/src/androidTest) for every new tag you add, we (hopefully) made it easy to do\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfotech-group%2Fandroid-drawable-dsl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfotech-group%2Fandroid-drawable-dsl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfotech-group%2Fandroid-drawable-dsl/lists"}