android组件实现圆角
效果预览
要实现如图所示的圆角

步骤
- 在
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 进行控制

浙公网安备 33010602011771号