效果预览
要实现如图所示的圆角
步骤
- 在
app/src/main/res/drawable
新建样式文件如rounded.xml
<?xml version="1.0" encoding="utf-8"?>
<!--实现圆角边框-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><!-- 这里用白色作为基础色,后续会通过背景 tint 改变颜色 --><solid android:color="@android:color/white" /><!-- 设置圆角半径,可根据需要调整 --><corners android:radius="8dp" />
</shape>
radius
对应四角圆角。此外还有topRightRadius
、bottomLeftRadius
等
- 在组件中使用
<TextView...android:background="@drawable/rounded.xml"android:backgroundTint="@color/green".../>
背景的颜色由 backgroundTint 进行控制