
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"
或
字体颜色
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
分隔符 横向:
java代码:
1. 3.android:layout_height="1dip" 4.android:background="?android:attr/listDivider" /> 纵向: java代码: 1. 3.android:background="?android:attr/listDivider" /> 4. 5.CheckBox 6.style="?android:attr/starStyle" 7. 8.//类似标题栏效果的TextView 9.style="?android:attr/listSeparatorTextViewStyle" 10. 11.//其它有用的样式 12.android:layout_height="?android:attr/listPreferredItemHeight" 13. 14.android:paddingRight="?android:attr/scrollbarSize" 15. 16.style="?android:attr/windowTitleBackgroundStyle" 17. 18.style="?android:attr/windowTitleStyle" 19. 20.android:layout_height="?android:attr/windowTitleSize" 21. 22.android:background="?android:attr/windowBackground"
