android-给字体设置投影
2016-03-30 16:31
399 查看
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也可以在代码中使用setShadowLayer(float radius, float dx, float dy, int color)方法
2,在配置文件中添加文字阴影
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/person_popularvalue"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5.0dip"
android:layout_marginLeft="10.0dip"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="1"
android:shadowRadius="1"
android:textColor="@color/white"
android:textSize="14sp" >
</TextView>
android:shadowColor 阴影的颜色
android:shadowDx 阴影的水平偏移量
android:shadowDy 阴影的垂直偏移量
android:shadowRadius 阴影的范围
需要注意的地方 :将android:shadowRadius=0 的时候是看不到阴影的
Button的文字阴影效果的添加与上面的一样。
3,示例:
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也可以在代码中使用setShadowLayer(float radius, float dx, float dy, int color)方法
2,在配置文件中添加文字阴影
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/person_popularvalue"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5.0dip"
android:layout_marginLeft="10.0dip"
android:shadowColor="@color/black"
android:shadowDx="0"
android:shadowDy="1"
android:shadowRadius="1"
android:textColor="@color/white"
android:textSize="14sp" >
</TextView>
android:shadowColor 阴影的颜色
android:shadowDx 阴影的水平偏移量
android:shadowDy 阴影的垂直偏移量
android:shadowRadius 阴影的范围
需要注意的地方 :将android:shadowRadius=0 的时候是看不到阴影的
Button的文字阴影效果的添加与上面的一样。
3,示例:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="你好Demo" android:textSize="39sp" android:textColor="@color/white" android:shadowColor="@color/white" android:shadowDx="5" android:shadowDy="1" android:shadowRadius="30" android:layout_gravity="center" android:layout_marginLeft="10dp" />
相关文章推荐
- android消息机制
- Android AndBase框架内部封装实现进度框、Toast框、弹出框、确认框(二)
- Android:Handler消息机制
- 聊聊android适配(下)
- Android 提升效率利器(持续更新)
- 一个简单的Android小实例
- 体验极速Android SDK的更新与下载
- 使用IntelliJ IDEA 13搭建Android集成开发环境(图文教程)
- 【Settings】设置APN
- android获取内置和外置SD卡路径
- Android中通过Exifinterface读取图片地理位置信息
- Android View的几种背景颜色设置
- android动画集合
- android:allowTaskReparenting实例
- 尼玛某前辈把ant 工程 改成android studio工程然后上传了 对我来说 尼玛这玩意就和屎一样
- Android实现获取验证码的倒计时功能
- Android深入浅出之Binder机制
- 深入理解android之IPC机制与Binder框架
- Android 权限 exproted 的作用
- Android RecyclerView 使用完全解析 体验艺术般的控件