android TextView 支持自定义字体和属性
来源:互联网 发布:独创科技网络 编辑:程序博客网 时间:2024/05/18 14:43
使用android 系统字体:
Android系统默认支持三种字体,分别为:“sans”, “serif”, “monospace
eg.
<!-- 使用默认的sans字体-->
<TextView android:id="@+id/sans"
android:text="Hello,World"
android:typeface="sans"
android:textSize="20sp"></TextView>
使用自定义字体属性:
<declare-styleable name="CustomizeTextView">
<attr name="fontType">
<enum name="none" value="0" />
<enum name="regular" value="1" />
<enum name="bold" value="2" />
</attr>
</declare-styleable>
xmls:namespace="http://schemas.android.com/apk/res/project.name.space"
<!-- 使用自定义字体属性-->
<CustomizeTextView android:id="@+id/sans"
android:text="Hello,World"
namespace:fontType="regular"
android:textSize="20sp"></TextView>
使用自定义字体:
public class CustomizeTextView extends TextView{
pulibc static TypeFace typeface1;
public static TypeFace typeface2;
{
typeface1 = Typeface.createFromAsset(context.getAssetManager(), "font/text1.ttf");
typeface2 = Typeface.createFromAsset(context.getAssetManager(), "font/text2.ttf");
}
private void init(Context context , AttributeSet attrs , int defStyle)
{
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyView);
int fontType = a.getInt(R.styleable.CustomizeTextView_fontType,default);
a.recycle();
switch(fontType){
case 1:
setTypeFace(typeface1);
break;
case 2:
setTypeFace(typeface2);
break;
default:
break;
}
}
}
- android TextView 支持自定义字体和属性
- TextView 支持自定义字体和属性
- Android自定义TextView字体
- Android—自定义TextView字体!
- android TextView设置自定义字体
- android TextView自定义字体样式
- Android TextView 自定义字体设置
- 自定义TextView属性和设置TextView属性
- android 自定义textview属性配置
- Android中设置TextView的字体和设置Paint画笔的字体属性
- android修改textview中某段字体的属性
- Android中自定义TextView的字体
- Android textView字体自定义结合HTml
- Android textView字体自定义结合HTml
- Android-自定义TextView(彩色字体与霓虹灯字体以及TextView的多项字体效果)
- Android基础控件——TextView的跑马灯效果、变量赋值、字体属性、超链接、Activity跳转、字体加粗、自定义字体
- 自定义TextView字体
- TextView设置自定义字体
- 深入浅出 Java Concurrency (17): 并发容器 part 2 ConcurrentMap (2)
- OC_NSString
- Java中的泛型是什么 ? 使用泛型的好处是什么?
- 二进制文件读取效率测试
- HTML基础总结
- android TextView 支持自定义字体和属性
- 三次样条插值(Cubic Spline Interpolation)及代码实现(C语言)
- 平面分割,空间分割问题(递推关系)(hdu1249、hdu1290、hdu2050) .
- powerdesign导出SQL时自动生成注释
- poj 2411——Mondriaan's Dream
- poj_1222_高斯消元
- EasyUI DataGrid可编辑单元格
- Java关键字synchronized使用总结
- 读书笔记:大端存储方式和小端存储方式和printf函数