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