代码实现:
Step 1:编写 矩形边框 的Drawable:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 设置一个黑色边框 --> <stroke android:width="2px" android:color="#000000"/> <!-- 渐变 --> <gradient android:angle="270" android:endColor="#C0C0C0" android:startColor="#FCD209" /> <!-- 设置一下边距,让空间大一点 --> <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp"/> </shape>
Step 2:编写 圆角矩形边框 的Drawable:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 设置透明背景色 --> <solid android:color="#87CEEB" /> <!-- 设置一个黑色边框 --> <stroke android:width="2px" android:color="#000000" /> <!-- 设置四个圆角的半径 --> <corners android:bottomLeftRadius="10px" android:bottomRightRadius="10px" android:topLeftRadius="10px" android:topRightRadius="10px" /> <!-- 设置一下边距,让空间大一点 --> <padding android:bottom="5dp" android:left="5dp" android:right="5dp" android:top="5dp" /> </shape>
本文介绍如何使用XML定义自定义矩形边框及圆角矩形边框的Drawable资源文件。通过设置边框颜色、宽度、背景渐变色、圆角半径等属性,可以轻松创建美观的UI元素。

2526

被折叠的 条评论
为什么被折叠?



