android中给TextView或许Button的文字添加阴影效果
来源:互联网 发布:mac文明 编辑:程序博客网 时间:2024/05/21 19:23
转自http://www.myexception.cn/android/1236047.html
学习目标:
1.什么是阴影?什么是文字阴影?
2.阴影的参数有哪些?模糊度,偏移量,阴影颜色
3.阴影设置的3种方法
android中给TextView或者Button的文字添加阴影效果
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.
在values文件夹下创建styles.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?><resources> <style name="StyleBarTitle"> <item name="android:layout_gravity">center_vertical</item> <item name="android:layout_width">0dp</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_weight">1</item> <item name="android:gravity">center_horizontal</item> <item name="android:textSize">20dip</item> <item name="android:textStyle">bold</item> <item name="android:textColor">#FFFFFF</item> <item name="android:shadowColor">#ff000000</item> //阴影颜色,前两位为透明度 <item name="android:shadowDx">5</item> //阴影的水平偏移量 <item name="android:shadowDy">5</item> //阴影的垂直偏移量 <item name="android:shadowRadius">3</item> //阴影的范围 <item name="android:background">@null</item> </style></resources>
TextView使用方式如下:
<TextView style="@style/StyleBarTitle" android:id="@+id/head_txt_title" android:text="About Us" android:singleLine="true" />
- android中给TextView或许Button的文字添加阴影效果
- android中给TextView或者Button的文字添加阴影效果
- android TextView中文字的阴影效果
- AndroidTips(1):给TextView文字添加阴影效果
- 给TextView中的文字添加阴影效果和样式Style的使用
- android 把TextView中的文字添加阴影效果
- TextView中的文字添加阴影效果及Style的使用
- Android 给文字添加阴影
- TextView文字阴影效果。
- Android TextView 显示文字阴影效果
- Android textview的阴影效果
- Android TextView显示文字过长时添加阴影渐变消失效果
- Android 给图片、文字、控件、布局添加阴影效果(悬浮效果)
- TextView显示文字过长时添加阴影渐变消失效果
- TextView显示文字过长时添加阴影渐变消失效果
- Android文字的阴影效果
- Android TextView 文字阴影
- 给文字加上阴影效果的方法
- RHEL5使用multipath配置ASMdisk
- Android逆向分析源码中资源代码还原小工具
- ORACLE重新编译无效对象的执行问题
- sqlite3数据库归纳
- I2C总线协议详解
- android中给TextView或许Button的文字添加阴影效果
- jQuery 入门教程(35): jQuery UI Dialog 示例(三)
- 在pcDuino上安装可燃气传感器
- twisted 学习笔记1 % 介绍以及安装
- Windows上面编译和简单测试一下leveldb-1.9.0
- jQuery 入门教程(36): jQuery UI Menu 示例
- jQuery 入门教程(37): jQuery UI Progressbar 示例
- android TimerTask 的简单应用,以及java.lang.IllegalStateException: TimerTask is scheduled already错误的解决方法
- oracle 取整的几种方法