Android 字体设置
Android 对中文字体支持很不好~~ 需要加入相应的字体库
(1)创建布局Layout
//创建线性布局
LinearLayout linearLayout=newLinearLayout(this);
//设定线性布局为垂直方向
linearLayout.setOrientation(LinearLayout.VERTICAL);
//以该线性布局做视图
setContentView(linearLayout);
(2)针对正常字体
//普通正常字体
normal=newTextView(this);
//设置字体内容,请注意:目前Android主要针对拉丁语系可使用字型设定,中文暂不支持
normal.setText("Normal Font FYI");
//设置字体大小
normal.setTextSize(20.0f);
//设置字型为默认,正常字体
normal.setTypeface(Typeface.DEFAULT,Typeface.NORMAL);
//增加该字体并显示到布局linearLayout中
linearLayout.addView(normal,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
(3)针对粗体字体
//粗体字体
bold=newTextView(this);
bold.setText("Bold Font FYI");
bold.setTextSize(20.0f);
//设置字体颜色为蓝色
bold.setTextColor(Color.BLUE);
//设置字型为默认粗体,粗体字体
bold.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);
linearLayout.addView(bold,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
(4)针对斜体字体
//斜体字体
italic=newTextView(this);
italic.setTextSize(20f);
italic.setText("Italic Font FYI");
//设置字体颜色为红色
italic.setTextColor(Color.RED);
//设置字型为等宽字型,斜体字体
italic.setTypeface(Typeface.MONOSPACE,Typeface.ITALIC);
linearLayout.addView(italic,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
(5)针对粗斜体字体
//粗斜体字体
italic_bold=newTextView(this);
italic_bold.setTextSize(20f);
italic_bold.setText("Italic & Bold Font FYI");
//设置字体颜色为黄色
italic_bold.setTextColor(Color.YELLOW);
//设置字型为等宽字型,斜体字体
italic_bold.setTypeface(Typeface.MONOSPACE,Typeface.BOLD_ITALIC);
linearLayout.addView(italic_bold,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
(6)针对中文仿“粗体”
//针对Android字型的中文字体问题
chinese=newTextView(this);
chinese.setText("中文粗体显示效果");
//设置字体颜色
chinese.setTextColor(Color.MAGENTA);
chinese.setTextSize(20.0f);
chinese.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);
//使用TextPaint的仿“粗体”设置setFakeBoldText为true。目前还无法支持仿“斜体”方法
tp=chinese.getPaint();
tp.setFakeBoldText(true);
linearLayout.addView(chinese,newLinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
(7)自定义创建字型
//自定义字体字型
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));
Android 字体设置的更多相关文章
- Android 字体设置-Typeface讲解
控件的字体设置的两种方式 常用的字体类型名称还有: Typeface.DEFAULT //常规字体类型 Typeface.DEFAULT_BOLD //黑体字体类型 Typeface.MONOSPAC ...
- Android字体设置
// 自定义字体custom = new TextView(this);//xx.ttf located at assets/fonts/typeface = Typeface.createFromA ...
- Android字体设置,Roboto字体使用
一.自定义字体 1.android Typeface使用TTF字体文件设置字体 我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体.第一步,在assets目录下新建fonts目录 ...
- android ADT 设置编辑字体
新配置的android ADT 设置编辑字体的时候 可能里面没有我们想要的Courier new 这种舒服的字体 那么就在 字体选项窗口的 做下端 有个显示更多字体的链接 然后就显示微软的所有字 ...
- Android开发之字体设置
默认字体 Android SDK自带了四种字体:"normal"“monospace",“sans”, “serif”,如下: 字体 看这四兄弟长的还是蛮像,我是看不 ...
- Android Studio设置自定义字体
Android Studio设置自定义字体 (1)进入设置页面,File->Settings (2)自定义字体Editor->Colors&Fonts->Font (3)点击 ...
- [Android] 字体使用dp单位避免设置系统字体大小对排版的影响
[Android] 字体使用dp单位避免设置系统字体大小对排版的影响 以魄族mx3为例,在设置->显示->字体大小中能够选择字号大小例如以下图: 图1. 魄族mx3 会导致软件在有固定定高 ...
- 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色
原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...
- android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .
① 字体设置: 修改代码 : GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...
随机推荐
- git变基、冲突解决
参考git rebase 版本..变基 git冲突解决先fetch,pull,如果文件冲突,手动处理冲突文件,然后再fetch,pull,发现拉不下来,这时需要将文件改为已合并,然后提交文件 具体操作 ...
- 服务器端调用Word组件读取Word权限、未将对象引用到对象实例终极解决方案
最近因为业务需要,需要在服务器上调用Word组件,结果遇到各种问题,比如检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败 ...
- URI、URL、URN
URI.URL.URN URI(Uniform Resource Identifie):统一资源标识符 URL(Uniform Resource Locator):统一资源定位符 URN(Unifor ...
- Memcached 搭建过程
原文链接:http://www.open-open.com/lib/view/open1324368235733.html 安装 memcached 服务端 yum -y install libeve ...
- JNI类型与C/C++映射关系
Java 类型 本地类型 描述 boolean jboolean C/C++8位整型 byte jbyte C/C++带符号的8位整型 char jchar C/C++无符号的16位整型 short ...
- clang: error: unable to execute command: Segmentation fault: 11
我在Archive的时候出现了上面这个错误, 解决方法很简单: After huge trying I have disabled the Bitcode in Project's Target-&g ...
- ASP.NET执行cmd命令
批处理命令,是执行速度最快效益最高的命令.因为批处理命令,说白了,就是ms-dos环境下的命令,有很多的批处理命令,都是纯DOS下的命令. 然而,批处理命令尽管功能强大,却存在不足之处.批处理命令只能 ...
- html5 利用canvas实现简单的人物走动
最近在学习html5,其中涉及到很关键的元素canvas-画布,在网上下载了一些游戏源代码,虽然能看懂,但是想单独地针对某个功能提取出来还是有难处的,于是乎自己又上网查找了一些例子,才将超级玛丽简单的 ...
- php global范例
Example #1 $GLOBALS 范例 <?phpfunction test() { $foo = "local variable"; echo '$foo in ...
- 【学习笔记】【Foundation】字符串
NSString 创建字符串: char *str="string" NSString* str=@“创建字符串”: NSString* str=[[NSString alloc] ...