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 字体设置的更多相关文章

  1. Android 字体设置-Typeface讲解

    控件的字体设置的两种方式 常用的字体类型名称还有: Typeface.DEFAULT //常规字体类型 Typeface.DEFAULT_BOLD //黑体字体类型 Typeface.MONOSPAC ...

  2. Android字体设置

    // 自定义字体custom = new TextView(this);//xx.ttf located at assets/fonts/typeface = Typeface.createFromA ...

  3. Android字体设置,Roboto字体使用

    一.自定义字体 1.android Typeface使用TTF字体文件设置字体 我们可以在程序中放入ttf字体文件,在程序中使用Typeface设置字体.第一步,在assets目录下新建fonts目录 ...

  4. android ADT 设置编辑字体

    新配置的android ADT 设置编辑字体的时候  可能里面没有我们想要的Courier new 这种舒服的字体 那么就在 字体选项窗口的  做下端 有个显示更多字体的链接  然后就显示微软的所有字 ...

  5. Android开发之字体设置

    默认字体 Android SDK自带了四种字体:"normal"“monospace",“sans”, “serif”,如下:   字体 看这四兄弟长的还是蛮像,我是看不 ...

  6. Android Studio设置自定义字体

    Android Studio设置自定义字体 (1)进入设置页面,File->Settings (2)自定义字体Editor->Colors&Fonts->Font (3)点击 ...

  7. [Android] 字体使用dp单位避免设置系统字体大小对排版的影响

    [Android] 字体使用dp单位避免设置系统字体大小对排版的影响 以魄族mx3为例,在设置->显示->字体大小中能够选择字号大小例如以下图: 图1. 魄族mx3 会导致软件在有固定定高 ...

  8. 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色

    原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...

  9. android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .

    ①  字体设置: 修改代码 :  GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...

随机推荐

  1. asp.net微信开发第二篇----消息应答

    当普通微信用户向公众账号发消息时,微信服务器将POST消息的XML数据包到开发者填写的URL上. 请注意: 1.关于重试的消息排重,推荐使用msgid排重. 2.微信服务器在五秒内收不到响应会断掉连接 ...

  2. ASP.NET获取根目录的方法集合

    编写程序的时候,经常需要用的项目根目录,自己总结如下: 1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径 方法 ...

  3. csms发布步骤

    1.wcf发布 通过点击 CSMS2.Application,右键发布按钮,将文件拷贝 2.打包文件 CSMS2.Resources 中 update.config 修改为对应 ServerUrl地址 ...

  4. 武汉科技大学ACM :1010: 零起点学算法12——求2个日期之间的天数

    Problem Description 水题 Input 输入2个日期,日期按照年月日,年月日之间用符号-隔开(题目包含多组数据) Output 求出这2个日期之间的天数(不包括自身),每组测试数据一 ...

  5. linux初识-02常用命令

    文件目录操作命令 ls 现实文件和目录列表 ls -l 列出文件的详细信息 ls -a 列出当前目录所有文件 包括隐藏的文件 mkdir 创建目录 -p 父目录不存在的情况下先生成父目录 cd 切换目 ...

  6. EcStore操作笔记

    1.去掉首页里面代码: <meta http-equiv="content-type" content="text/html; charset=utf-8" ...

  7. phpcms v9教程 联动搜索在房地产网站开发中的应用

    开发简述:使用phpcms v9系统,修改源文件5个,创建模型:楼盘.出售.出租.中介.小区,增加联动菜单:楼盘,增加用户组:房产中介.实现功能:游客发布信息.会员申请中介.楼盘全方位展示.报名团购. ...

  8. Swift—do-try-catch错误处理模式-备

    Swift 1.x的错误处理模式存在很多弊端,例如:为了在编程时候省事,给error参数传递一个nil,或者方法调用完成后不去判断error是否为nil,不进行错误处理. let contents = ...

  9. 消息通信机制NSNotificationCenter -备

    消息通信机制NSNotificationCenter的学习.最近写程序需要用到这类,研究了下,现把成果和 NSNotificationCenter是专门供程序中不同类间的消息通信而设置的,使用起来极为 ...

  10. VLC命令行的应用

    vlc -vvv rtsp://218.204.223.237:554/live/1/0547424F573B085C/gsfp90ef4k0a6iap.sdp --sout #transcode{v ...