代码设置ConstraintLayout的style样式
时间: 2023-12-19 08:03:50
浏览: 29
可以通过在布局文件中设置 `style` [属性]([http](https://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/5280ca4eda584c6baf7c2ec8010927f9?spm=1055.2569.3001.10083)来应用 `ConstraintLayout` 的[样式](https://geek.csdn.net/educolumn/24a10ad6a5bc75b9f6c92ee7d63d8e8b?spm=1055.2569.3001.10083)。
首先,在 `res/values/styles.xml` 文件中定义一个名为 `MyConstraintLayoutStyle` 的[样式](https://geek.csdn.net/educolumn/24a10ad6a5bc75b9f6c92ee7d63d8e8b?spm=1055.2569.3001.10083):
```xml
<style name="MyConstraintLayoutStyle" parent="Wid[get](https://geek.csdn.net/educolumn/31aebce56f4ecc5451aac3a194ff6259?spm=1055.2569.3001.10083).ConstraintLayout">
<item name="android:padding">16dp</item>
<item name="android:background">#F2F2F2</item>
</style>
```