演示范例(为个人原创,当然遇见问题时参考了一些国内/国外的一些范例):
(1)创建布局Layout
//创建线性布局
LinearLayout linearLayout=new LinearLayout(this);
//设定线性布局为垂直方向
linearLayout.setOrientation(LinearLayout.VERTICAL);
//以该线性布局做视图
setContentView(linearLayout);
(2)针对正常字体
//普通正常字体
normal=new TextView(this);
//设置字体内容,请注意:目前Android主要针对拉丁语系可使用字型设定,中文暂不支持
normal.setText("Normal Font FYI");
//设置字体大小
normal.setTextSize(20.0f);
//设置字型为默认,正常字体
normal.setTypeface(Typeface.DEFAULT,Typeface.NORMAL);
//增加该字体并显示到布局linearLayout中
linearLayout.addView(normal, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
(3)针对粗体字体
//粗体字体
bold=new TextView(this);
bold.setText("Bold Font FYI");
bold.setTextSize(20.0f);
//设置字体颜色为蓝色
bold.setTextColor(Color.BLUE);
//设置字型为默认粗体,粗体字体
bold.setTypeface(Typeface.DEFAULT_BOLD, Typeface.BOLD);
linearLayout.addView(bold, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));