📒 博客首页:✎﹏ℳ๓敬坤的博客 🎈
😊 我只是一个代码的搬运工 🎃
🎉 欢迎来访的读者关注、点赞和收藏 🤞
😉有问题可以私信交流 😆
📃 文章标题:【鸿蒙实战开发之常见设置圆角(一)】 🖍
图片设置圆角
//首先找到我们图片组件
Image img_logo = (Image)findComponentById(ResourceTable.Id_login_logo);
//通过setCornerRadius函数设置圆角单位f
img_logo.setCornerRadius(1000f);
输入框设置圆角
第一步设置我们background_element属性引入外部border_radius_12.xml文件
<TextField
ohos:id="$+id:user"
ohos:height="50vp"
ohos:width="312vp"
ohos:background_element="$graphic:border_radius_12"
>
</TextField>
第二步设置外部border_radius_12.xml设置如下
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:shape="rectangle">
<!-- 设置输入框的圆角 -->
<corners
ohos:radius="12vp"
/>
<!-- 设置输入框的边框颜色 -->
<solid
ohos:color="#FFFFFF"/>
</shape>
按钮设置圆角和圆角
//找到我们的按钮
Button login_btn = (Button) findComponentById(ResourceTable.Id_login_btn);
//ShapeElement提供一个带有颜色渐变的Element实例
ShapeElement shapeElement = new ShapeElement();
//设置渐变的起始结束方向
shapeElement.setGradientOrientation(ShapeElement.Orientation.BOTTOM_TO_TOP);
RgbColor[] rgbColors = new RgbColor[2];
//0x后面两面代表透明度十六进制FF代表1 33代表0.2后面是十六进制颜色
rgbColors[0] = RgbColor.fromArgbInt(0x33F60300);
rgbColors[1] = RgbColor.fromArgbInt(0x33FF6C5A);
//设置渐变色
shapeElement.setRgbColors(rgbColors);
//设置圆角
shapeElement.setCornerRadius(100);