TextView 支持自定义字体和属性
来源:互联网 发布:mysql if then else 编辑:程序博客网 时间:2024/06/08 16:50
使用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 支持自定义字体和属性
- 自定义TextView属性和设置TextView属性
- 自定义TextView字体
- TextView设置自定义字体
- Android自定义TextView字体
- TextView的自定义字体
- 自定义的TextView的字体
- 安卓textview自定义字体
- 自定义textview字体闪烁效果
- Android—自定义TextView字体!
- android TextView设置自定义字体
- android TextView自定义字体样式
- Android TextView 自定义字体设置
- Android中设置TextView的字体和设置Paint画笔的字体属性
- TextView支持的XML属性
- 自定义TextView的TextSize属性getDimension和setTextSize的冲突
- android 自定义textview属性配置
- app创业之用户杂谈
- scp命令
- 2015年Android开发新技术
- nginx设计解读--模块化设计及程序初始化
- GTK简单版计算器
- TextView 支持自定义字体和属性
- Struts2与servlet共存的解决方案
- SQLite 运算符
- 26 - 复杂链表的复制
- 【Android】在不同的线程池中执行AsyncTask
- Jsp中图片显示问题以及显示绝对路径图片问题
- vs2010运行mat文件的一个测试代码
- USACO 4.2.2The Perfect Stall 完美的牛栏(二分图最大匹配)
- linux下安装tomcat并设置开机自启动