android一个字体的描边与阴影效果,android开发步步为营之104:文字加阴影效果和描边效果的实现...

这篇博客介绍了如何在Android应用中为文字添加阴影和描边效果。通过XML属性和代码方式展示了设置阴影效果,同时讲解了使用TextView叠加和自定义绘制方法实现文字描边的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有时候为了文字的美观,我们需要给文字加阴影,或者加边框,这个效果怎么实现呢?最近项目里也用到了,这里总结一下。

一、文字加阴影效果

1、通过xml实现

android:id="@+id/txt_shadom"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:shadowColor="#ff0000ff"

android:shadowDx="2"

android:shadowDy="2"

android:shadowRadius="1"

android:text="Shadom"

android:textColor="#000000"

android:textSize="30sp" />

2、通过代码实现

//设置阴影效果

TextView txtShadom =(TextView)findViewById(R.id.txt_shadom);

txtShadom.setShadowLayer(2,1,1, Color.parseColor("#ff0000"));

setShadowLayer

void setShadowLayer (float radius,

float dx,

float dy,

int shadowColor)

This draws a shadow layer below the main layer, with the specified offset and color, and blur radius. If radius is 0, then the shadow layer is removed.

Can be used to create a blurred shadow underneath text. Support for use with other drawing operations is constrained to the software renderin

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值