android中文字体
来源:互联网 发布:mac 身份不明 编辑:程序博客网 时间:2024/05/01 05:22
(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 设置中文字体。。。。
- Android 增加中文字体
- android:设置中文字体的方法
- android TextView设置中文字体加粗
- Android Studio 中文字体显示乱码
- Android Studio中文字体显示乱码
- 中文字体
- android: 设置中文字体效果的一些方法
- android: 设置中文字体效果的一些方法
- NME使用Android设备自带中文字体
- android TextView设置中文字体加粗实现方法
- android TextView设置中文字体加粗如何实现
- android TextView设置中文字体加粗实现方法
- 处理Android Studio中文字体为繁体字
- android TextView设置中文字体加粗实现方法
- Android中TextView中文字体粗体的设置方法
- android ADT eclipse相关设置 背景色 中文字体等
- POJ 2777 Count Color
- svn一些使用问题
- C语言写的trim()函数
- ExtJS中get、getDom、getCmp、getBody、getDoc使用 javascript
- 从网上整理的一些delphi字符串加密解密方法
- android中文字体
- 硅谷13大令人惊叹的女性
- 标记关键数字
- 枚举
- [MS-TDS]: Tabular Data Stream Protocol Specification
- 扎克伯格成功的六大因素
- 几个算法测试题及答案
- 程序猿装B指南
- 指南针-Memsic3280调试笔录