android.graphics.Typeface实践
来源:互联网 发布:服务器怎么访问数据库 编辑:程序博客网 时间:2024/06/06 04:39
字体风格Typeface种类
int Style类型
BOLD
BOLD_ITALIC
ITALIC
NORMAL粗体
粗斜体
斜体
普通字体
Typeface类型
DEFAULT
DEFAULT_BOLD
MONOSPACE
SANS_SERIF
SERIF默认字体
默认粗体
单间隔字体
无衬线字体
衬线字体
Typeface.create(Typeface family,int style)
创建一个混合型新的字体:有4*5中搭配
Typeface.setTypeface (Typeface tf, int style)
设置一个混合型字体:有4*5中搭配
Typeface.setTypeface(Typeface tf)
设置一个只有Typeface风格的字体:有五种形式
编程实现以上静态域字体
① 创建新工程
② 修改mianActivity.java,实现多种字体TextView显示
复制代码③ 结果
int Style类型
BOLD
BOLD_ITALIC
ITALIC
NORMAL粗体
粗斜体
斜体
普通字体
Typeface类型
DEFAULT
DEFAULT_BOLD
MONOSPACE
SANS_SERIF
SERIF默认字体
默认粗体
单间隔字体
无衬线字体
衬线字体
Typeface.create(Typeface family,int style)
创建一个混合型新的字体:有4*5中搭配
Typeface.setTypeface (Typeface tf, int style)
设置一个混合型字体:有4*5中搭配
Typeface.setTypeface(Typeface tf)
设置一个只有Typeface风格的字体:有五种形式
编程实现以上静态域字体
① 创建新工程
② 修改mianActivity.java,实现多种字体TextView显示
- package zyf.TypefaceStudy;
- /*导入要使用的包*/
- import android.app.Activity;
- import android.graphics.Color;
- import android.graphics.Typeface;
- import android.os.Bundle;
- import android.view.ViewGroup;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- public class TypefaceStudy extends Activity {
- /** Called when the activity is first created. */
- /*
- * android.graphics.Typeface java.lang.Object
- Typeface类指定一个字体的字体和固有风格.
- * 该类用于绘制,与可选绘制设置一起使用,
- 如textSize, textSkewX, textScaleX 当绘制(测量)时来指定如何显示文本.
- */
- /* 定义实例化一个 布局大小,用来添加TextView */
- final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
- /* 定义TextView对象 */
- private TextView bold_TV, bold_italic_TV, default_TV,
- default_bold_TV,italic_TV,monospace_TV,
- normal_TV,sans_serif_TV,serif_TV;
- /* 定义LinearLayout布局对象 */
- private LinearLayout linearLayout;
- /* 定义LinearLayout布局参数对象 */
- private LinearLayout.LayoutParams linearLayouttParams;
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- /* 定义实例化一个LinearLayout对象 */
- linearLayout = new LinearLayout(this);
- /* 设置LinearLayout布局为垂直布局 */
- linearLayout.setOrientation(LinearLayout.VERTICAL);
- /*设置布局背景图*/
- linearLayout.setBackgroundResource(R.drawable.back);
- /* 加载LinearLayout为主屏布局,显示 */
- setContentView(linearLayout);
- /* 定义实例化一个LinearLayout布局参数 */
- linearLayouttParams =
- new LinearLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT);
- constructTextView();
- setTextSizeOf();
- setTextViewText() ;
- setStyleOfFont();
- setFontColor();
- toAddTextViewToLayout();
- }
- public void constructTextView() {
- /* 实例化TextView对象 */
- bold_TV = new TextView(this);
- bold_italic_TV = new TextView(this);
- default_TV = new TextView(this);
- default_bold_TV = new TextView(this);
- italic_TV = new TextView(this);
- monospace_TV=new TextView(this);
- normal_TV=new TextView(this);
- sans_serif_TV=new TextView(this);
- serif_TV=new TextView(this);
- }
- public void setTextSizeOf() {
- // 设置绘制的文本大小,该值必须大于0
- bold_TV.setTextSize(24.0f);
- bold_italic_TV.setTextSize(24.0f);
- default_TV.setTextSize(24.0f);
- default_bold_TV.setTextSize(24.0f);
- italic_TV.setTextSize(24.0f);
- monospace_TV.setTextSize(24.0f);
- normal_TV.setTextSize(24.0f);
- sans_serif_TV.setTextSize(24.0f);
- serif_TV.setTextSize(24.0f);
- }
- public void setTextViewText() {
- /* 设置文本 */
- bold_TV.setText("BOLD");
- bold_italic_TV.setText("BOLD_ITALIC");
- default_TV.setText("DEFAULT");
- default_bold_TV.setText("DEFAULT_BOLD");
- italic_TV.setText("ITALIC");
- monospace_TV.setText("MONOSPACE");
- normal_TV.setText("NORMAL");
- sans_serif_TV.setText("SANS_SERIF");
- serif_TV.setText("SERIF");
- }
- public void setStyleOfFont() {
- /* 设置字体风格 */
- bold_TV.setTypeface(null, Typeface.BOLD);
- bold_italic_TV.setTypeface(null, Typeface.BOLD_ITALIC);
- default_TV.setTypeface(Typeface.DEFAULT);
- default_bold_TV.setTypeface(Typeface.DEFAULT_BOLD);
- italic_TV.setTypeface(null, Typeface.ITALIC);
- monospace_TV.setTypeface(Typeface.MONOSPACE);
- normal_TV.setTypeface(null, Typeface.NORMAL);
- sans_serif_TV.setTypeface(Typeface.SANS_SERIF);
- serif_TV.setTypeface(Typeface.SERIF);
- }
- public void setFontColor() {
- /* 设置文本颜色 */
- bold_TV.setTextColor(Color.BLACK);
- bold_italic_TV.setTextColor(Color.CYAN);
- default_TV.setTextColor(Color.GREEN);
- default_bold_TV.setTextColor(Color.MAGENTA);
- italic_TV.setTextColor(Color.RED);
- monospace_TV.setTextColor(Color.WHITE);
- normal_TV.setTextColor(Color.YELLOW);
- sans_serif_TV.setTextColor(Color.GRAY);
- serif_TV.setTextColor(Color.LTGRAY);
- }
- public void toAddTextViewToLayout() {
- /* 把TextView加入LinearLayout布局中 */
- linearLayout.addView(bold_TV, linearLayouttParams);
- linearLayout.addView(bold_italic_TV, linearLayouttParams);
- linearLayout.addView(default_TV, linearLayouttParams);
- linearLayout.addView(default_bold_TV, linearLayouttParams);
- linearLayout.addView(italic_TV, linearLayouttParams);
- linearLayout.addView(monospace_TV, linearLayouttParams);
- linearLayout.addView(normal_TV, linearLayouttParams);
- linearLayout.addView(sans_serif_TV, linearLayouttParams);
- linearLayout.addView(serif_TV, linearLayouttParams);
- }
- }
- android.graphics.Typeface实践
- Android入门--android.graphics.Typeface实践
- android.graphics.Typeface实践 字体风格
- android.graphics.Typeface
- android.graphics.Typeface应用
- parseSdkContent failed Could not initialize class android.graphics.Typeface
- parseSdkContent failed Could not initialize class android.graphics.Typeface
- parseSdkContent failed Could not initialize class android.graphics.Typeface
- parseSdkContent failed Could not initialize class android.graphics.Typeface异常
- 解决"Could not initialize class android.graphics.Typeface"
- parseSdkContent failed Could not initialize class android.graphics.Typeface
- Android Api Demos登顶之路(九十二)Graphics-->TypeFace
- parseSdkContent failed Could not initialize class android.graphics.Typeface
- 解决"Could not initialize class android.graphics.Typeface"
- Android 5.0 parseSdkContent failed Could not initialize class android.graphics.Typeface
- Android 5.0 parseSdkContent failed Could not initialize class android.graphics.Typeface
- 创建Android 项目,遇到parseSdkContent failed Could not initialize class android.graphics.Typeface
- 关于 parseSdkContent failed Could not initialize class android.graphics.Typeface 报错
- Ubuntu下配置android sdk 开发环境
- 再论经典冒泡排序算法
- FakeAlert Total Protect and Totalprotectav.com Hijacker Error Fixer
- jbpm3.2 总结
- Example of Recursion.
- android.graphics.Typeface实践
- wifi移植
- Android 照相机触摸浮层之探索
- Android开发之跑马灯效果
- 关于main方法
- 吊球
- test
- 20110719数据结构10级复习赛题级解题报告ccnuoj
- pku2492 并查集