您的位置:首页 > 移动开发 > Android开发

Android设置字体

2015-10-29 00:00 357 查看
摘要: 我没有试过,只是觉得是一种积累。有兴趣可以自己试一下

android:textAppearance
设置文字外观。如“?android:attr/textAppearanceLargeInverse
”这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。可设置的值如下:textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/textAppearanceSmallInverse

textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); //下划线

textView.getPaint().setAntiAlias(true);//抗锯齿

textview.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线

setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG);  // 设置中划线并加清晰

textView.getPaint().setFlags(0);  // 取消设置的的划线


自定义创建字型

//自定义字体字型

custom=newTextView(this);

//字体MgOpenCosmeticaBold.ttf放置于assets/font/路径下

typeface=Typeface.createFromAsset(getAssets(),"font/MgOpenCosmeticaBold.ttf");

custom.setTypeface(typeface);

custom.setText("Custom Font FYI");

custom.setTextSize(20.0f);

//设置字体颜色

custom.setTextColor(Color.CYAN);

linearLayout.addView(custom,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息