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. 数据库操作封装类 DBHelper.cs

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Co ...

  2. 单篇文章JS模拟分页

    废话部分 前两天做了一个前台分页插件,支持ajax读取数据绑定前台 和 url带页码参数跳转两种方式.于是稍加改动,做了一个单篇文章js模拟分页的代码,为什么说是模拟分页呢?因为在服务器响应HTML请 ...

  3. 使用Canvas实现下雪功能

    示例代码: <html> <head> <meta http-equiv="Content-Type" content="text/html ...

  4. 如何查看linux系统下的各种日志文件 linux 系统日志的分析大全

    日志分类: 1. 连接时间的日志 连接时间日志一般由/var/log/wtmp和/var/run/utmp这两个文件记录,不过这 两个文件无法直接cat查看,并且该文件由系统自动更新,可以通过如下: ...

  5. HDU_2068_RPG错排

    Problem Description 今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁.RPG给他机会让他猜猜,第一次猜:R ...

  6. eclipse - An internal error occurred during: "Running Android Lint"

    概述 也不晓得为什么,编译eclipse,设置打开,就自动报错: An internal error occurred during: "Running Android Lint" ...

  7. iptables 下开放ftp

    这两天在给客户安装服务器时也顺便给他们使用iptables,不用不知道,一用才发现iptables还有很多东西可以学的,比如开放ftp.iptables 的filter表的INPUT链的默认策略设为了 ...

  8. Entity Framework 新增实体,新增抽象实体

    抽象实体不能new 抽象类:人,实体类:学生 人 p_人= new 学生();   添加数据,学生和人都添加 抽象类可以提供一个抽象的方法,但是并没有实现,类似接口,但又不同于接口.子类继承父类时必须 ...

  9. react-redux源码解析

    有理解不对的地方,欢迎大家指正!!! react为什么需要redux辅助???react是view层的单向数据流框架,数据需要一层一层往子组件传递(子组件并不会自动继承).子组件需要操作父组件的数据时 ...

  10. Convert String to Long

    问题: Given a string, write a routine that converts the string to a long, without using the built in f ...