# DropShapeXML
**Repository Path**: xcode_xiao/DropShapeXML
## Basic Information
- **Project Name**: DropShapeXML
- **Description**: 丢弃你的Shape.xml文件吧
- **Primary Language**: Kotlin
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 0
- **Created**: 2022-04-10
- **Last Updated**: 2023-08-08
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Android, Shape, Selector, XML, Kotlin
## README
# 丢掉你的Shape selector layer_list XML文件
项目里的```shape.xml``` ```selector.xml``` ```layer_list.xml``` 文件太多啦
想个办法替代吧:
### 1. shape.xml 的替代法
- 旧写法 - shape.xml
```xml
```
- 新写法-kotlin
```kotlin
textView.background = shape {
shape = RECTANGLE
solid { color = Color.parseColor("#f00000") }
corners { radius = 15f.dp }
}
```
> xml 里所有的属性都支持
### 2. selector.xml 的替代法
- 旧写法 - selector.xml
normal.xml
```xml
```
pressed.xml
```xml
```
selector.xml
```xml
```
- 新写法 - kotlin
```kotlin
textView.background = selector {
item {
drawable = shape {
shape = RECTANGLE
solid { color = Color.parseColor("#f00000") }
corners { radius = 15f.dp }
}
state_pressed = false
}
item {
drawable = shape {
shape = RECTANGLE
solid { color = Color.parseColor("#00f000") }
corners { radius = 15f.dp }
}
state_pressed = true
}
}
```
### 3. layer_list.xml 的替代法
- 旧写法 - layer_list.xml
```
-
-
```
- 新写法 - kotlin
```kotlin
layerList {
item {
drawable = shape {
solid { color = Color.parseColor("#C15454") }
corners { radius = 15f.dp }
}
}
item {
top = 50.dp
drawable = shape {
solid { color = Color.parseColor("#155473") }
corners {
leftBottomRadius = 15f.dp
rightBottomRadius = 15f.dp
}
}
}
}
```
### 4. selector_color.xml 颜色选择的替代法
- 旧写法 - selector_color.xml
```xml
```
- 新写法 - kotlin
```kotlin
textView.setTextColor(colorSelector {
item {
state_pressed = true
color = Color.WHITE
}
item {
state_pressed = false
color = Color.GREEN
}
})
```
### 5. bitmap.xml 图片的替代法
- 旧写法 - bitmap.xml
```xml
```
- 新写法 - kotlin
```kotlin
bitmap {
src = R.drawable.icon_setting
tint = Color.WHITE
}
```