Android 字体相关知识汇总

1.自定义字体

android Typeface使用TTF字体文件设置字体

我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体。
第一步,在assets目录下新建fonts目录,把ttf字体文件放到这。
第二步,程序中调用:
AssetManager mgr=getAssets();//得到AssetManager
Typeface tf=Typeface.createFromAsset(mgr, "fonts/ttf.ttf");//根据路径得到Typeface
tv.setTypeface(tf);//设置字体     

2.在xml文件中使用android:textStyle=”bold” 可以将英文设置成粗体,  但是不能将中文设置成粗体,  
将中文设置成粗体的方法是:  
TextView tv = (TextView)findViewById(R.id.TextView01);  
 tv.getPaint().setFakeBoldText(true);//中文仿“粗体”--使用TextPaint的仿“粗体”设置setFakeBoldText为true。

3.对于能够显示文字的控件(如TextView EditText RadioButton Button CheckBox Chronometer等等),你有时需要控制字体的大小。Android平台定义了三种字体大小。

java代码:

"?android:attr/textAppearanceLarge"
"?android:attr/textAppearanceMedium"
"?android:attr/textAppearanceSmall"
使用方法为:
java代码:
android:textAppearance="?android:attr/textAppearanceLarge" 
android:textAppearance="?android:attr/textAppearanceMedium" 
android:textAppearance="?android:attr/textAppearanceSmall"

style="?android:attr/textAppearanceLarge" 
style="?android:attr/textAppearanceMedium" 
style="?android:attr/textAppearanceSmall"
字体颜色

java代码:
android:textColor="?android:attr/textColorPrimary" 
android:textColor="?android:attr/textColorSecondary" 
android:textColor="?android:attr/textColorTertiary" 
android:textColor="?android:attr/textColorPrimaryInverse" 
android:textColor="?android:attr/textColorSecondaryInverse"

ProgressBar 
style="?android:attr/progressBarStyleHorizontal" 
style="?android:attr/progressBarStyleLarge" 
style="?android:attr/progressBarStyleSmall" 
style="?android:attr/progressBarStyleSmallTitle"
分隔符 横向:

java代码:
  1. <View 
  2. android:layout_width="fill_parent" 
  3. android:layout_height="1dip" 
  4. android:background="?android:attr/listDivider" />

纵向:

java代码:
  1. <View android:layout_width="1dip" 
  2. android:layout_height="fill_parent" 
  3. android:background="?android:attr/listDivider" />

  4. CheckBox 
  5. style="?android:attr/starStyle"

  6. //类似标题栏效果的TextView 
  7. style="?android:attr/listSeparatorTextViewStyle"

  8. //其它有用的样式 
  9. android:layout_height="?android:attr/listPreferredItemHeight"

  10. android:paddingRight="?android:attr/scrollbarSize"

  11. style="?android:attr/windowTitleBackgroundStyle"

  12. style="?android:attr/windowTitleStyle"

  13. android:layout_height="?android:attr/windowTitleSize"

  14. android:background="?android:attr/windowBackground"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值