public class FontTest extends Activity {     

           /** Called when the activity is first created. */     

          @Override     

          public void onCreate(Bundle savedInstanceState) {     

          super.onCreate(savedInstanceState);     

          setContentView(R.layout.main);     

          /*  

           * 事先在assets底下创建一fonts文件夹 并放入要使用的字体文件(.ttf)  

           * 并提供相对路径给creatFromAsset()来创建Typeface对象  

           */  

          Typeface font = Typeface.createFromAsset(getAssets(), "fonts/sans.ttf");    

           // 字体文件必须是true type font的格式(ttf);   

          // 当使用外部字体却又发现字体没有变化的时候(以 Droid Sans代替),通常是因为这个字体android没有支持,而非你的程序发生了错误            

           TextView text = (TextView)findViewById(R.id.text);     

            text.setTypeface(font);     

            text.setText("Hello Android!");     

            text.setTextSize(40);     

            }     

}   

更多相关文章

  1. FileUtil:文件处理工具类
  2. streamingAssetsPath 内文件读取
  3. Android(安卓)ADB命令大全
  4. file system
  5. MediaRecorder和MediaPlayer的简单使用
  6. Kotlin Parameter specified as non-null is null
  7. 编译android4.0出现jdk版本问题
  8. Android(安卓)O notification用法
  9. Android(安卓)APP修改全局字体

随机推荐

  1. android 输入框自动匹配-AutoCompleteTex
  2. android 自动更新网址保存
  3. Android(安卓)TV RecyclerView 焦点处理
  4. android View 绘制完成监听
  5. Android 获取url中的参数
  6. android > ImageView 加载本地/服务器图
  7. 改变tab中indicator文本的颜色
  8. android 资源文件的种类
  9. android 初级入门
  10. Android上实现MVP模式的途径