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));
转载于:https://www.cnblogs.com/jh5240/archive/2012/09/08/2676831.html
Android 字体设置相关推荐
- android roboto字体下载,Android字体设置及Roboto字体使用方法
本文实例讲述了Android字体设置及Roboto字体使用方法.分享给大家供大家参考.具体分析如下: 一.自定义字体 1.android Typeface使用TTF字体文件设置字体 我们可以在程序中放 ...
- android 字体设置ttf
Android系统默认字体支持四种字体,分别为: noraml (普通字体,系统默认使用的字体) sans(非衬线字体) serif (衬线字体) monospace(等宽字体) 除此之外还可以使用其 ...
- android 字体变细,android 字体设置为中等粗细
Android TextView设置字体粗细只有三种状态,textStyle取值只有bold.nomral.italic.客户需求是字体是medium粗细,只因ios是有medium属性,Androi ...
- android 字体设置方正,Android设置TextView的字体
做项目的时候,需要使用到手写字体来让内容更加的美观.可是程序中默认使用的是系统的默认字体,怎么将TextView(或EditText)的字体设置成自己想要的字体呢?步骤如下: 下载字体文件(.ttf格 ...
- h5 android 字体设置,解决因为手机设置字体大小导致h5页面在webview中变形的BUG
解决因为手机设置字体大小导致h5页面在webview中变形的BUG 首先,我们做了一个H5页面,在各种手机浏览器中打开都没问题.我们采用了rem单位进行布局,通过JS来动态计算网页的视窗宽度,动态设置 ...
- android单线字体,Android字体设置
// 自定义字体 custom = new TextView(this); //xx.ttf located at assets/fonts/ typeface = Typeface.createFr ...
- android 字体设置为楷体
Typeface typeFace = Typeface.createFromFile("/mnt/sdcard/kt.ttf"); // .createFromAsset(get ...
- 【Android】字体设置 Text font
通过android:typeface属性来设置字体: <TextViewandroid:id="@+id/textView15"android:layout_width=&q ...
- android studio 设置控制台字体大小
今天,简单讲讲android studio 如何设置控制台字体大小. 这个其实很简单. 只要在android studio 这样设置:Settings->Editor->Color &am ...
最新文章
- int (*p)[4] 与 int* p[4]
- Java算法之旋转数组
- 和公婆住在一起是什么体验?
- 产品销售的过程中,价值是不断被定义和挖掘的
- k近邻算法matlab实现_k近邻算法
- Python第三方库使用——splinter
- 无法安装冰点还原_系统还原软件介绍与功能
- SQL判断字符在字符串中的位置
- 能处理姓氏异读的汉字转拼音工具:hanz2piny
- mysql查询各专业人数_SQL统计各专业学生人数
- Mysql之分组查询
- Java 移位、逻辑运算符详解(~史上最全|吹牛逼)
- leetcode 1419 数青蛙
- Scala中过滤操作filter与filterNot函数
- java 连接Linux服务器并执行指令
- 弘辽科技:淘宝新店运营推广的几大技巧
- Exception UserExistException is not compatible with throws clause in UserService.findUserByName(Stri
- KD树+BBF+KNN使用C#实现(3)
- 1080p笔记本哪个linux,System76经典Linux笔记本Lemur Pro回归 采用14.1英寸1080p显示屏
- VK1668带键盘扫描接口的LED(发光二极管显示器)驱动控制IC功能及作用介绍
热门文章
- yum安装virtualbox_CentOS7安装virtualbox
- linux 查看磁盘空间_【linux磁盘划分】3分钟看懂!
- java count 在哪一类里_count 是java关键字吗
- 建行优盾制单重要还是复核重要_想秒批建行5万+白金信用卡,你得满足这些条件!...
- zklib php,php 安装zookeeper扩展报错
- 使用python制作聊天框解谜游戏_使用Python写一个小游戏alien invasion!
- golang mysql分表_go分库分表 主从分离例子
- group by后可以join吗_去韩国留学毕业后可以留在韩国吗
- html绝对定位怎么页面居中,html – 如何将绝对定位的元素居中?
- linux下的打包和解压缩命令,浅析Linux打包压缩解压缩命令大全(收藏)