android 写字体投影,android-给字体设置投影

本文介绍了在Android中为TextView和Button添加文字阴影的方法,包括通过代码和XML配置文件实现。详细讲解了setShadowLayer方法的参数含义,以及在XML中设置阴影效果的相关属性。
摘要由CSDN通过智能技术生成

1,在代码中添加文字阴影

TextView 有一个方法

/**

* Gives the text a shadow of the specified radius and color, the specified

* distance from its normal position.

*

* @attr ref android.R.styleable#TextView_shadowColor

* @attr ref android.R.styleable#TextView_shadowDx

* @attr ref android.R.styleable#TextView_shadowDy

* @attr ref android.R.styleable#TextView_shadowRadius

*/

public void setShadowLayer(float radius, float dx, float dy, int color) {

mTextPaint.setShadowLayer(radius, dx, dy, color);

mShadowRadius = radius;

mShadowDx = dx;

mShadowDy = dy;

invalidate();

}

mTextView.setShadowLayer(10F, 11F,5F, Color.YELLOW); 第一个参数为模糊度,越大越模糊。 第二个参数是阴影离开文字的x横向距离。 第三个参数是阴影离开文字的Y横向距离。 第四个参数是阴影颜色。(如果模糊度为0是看不到阴影效果的)

Button是继承TextView的,所以Button也可以在代码中使用setShadow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值