Loading

android组件实现圆角

效果预览

要实现如图所示的圆角
image

步骤

  1. 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对应四角圆角。此外还有topRightRadiusbottomLeftRadius

  1. 在组件中使用
<TextView
	...
	android:background="@drawable/rounded.xml"
	android:backgroundTint="@color/green"
	.../>

背景的颜色由 backgroundTint 进行控制

posted @ 2025-03-09 16:24  F丶cat  阅读(57)  评论(0)    收藏  举报