Android中字体设置Font
2015-07-08 14:03
393 查看
1.一般使用默认字体,可以使用以下四种安卓系统提供的字体。
2.如果需要设置其他的字体,则需要先得到字体的 ttf文件,例如 Arial.ttf文件等。
把ttf文件放在assets\fonts目录下。
android:typeface="normal" android:typeface="sans" android:typeface="serif" android:typeface="monospace"
2.如果需要设置其他的字体,则需要先得到字体的 ttf文件,例如 Arial.ttf文件等。
把ttf文件放在assets\fonts目录下。
public class FontTest { public static void changeFont(ViewGroup root,Activity act){ Typeface tf = null; //创建Typeface对象 tf = Typeface.createFromAsset(act.getAssets(), "fonts/Arial.ttf"); for(int i=0;i<root.getChildCount();i++){ View v = root.getChildAt(i); if(v instanceof TextView){ ((TextView)v).setTypeface(tf); } else if(v instanceof EditText){ ((EditText)v).setTypeface(tf); } else if(v instanceof ViewGroup){ changeFont((ViewGroup)v, act); } } } } public class MainActivity extends Activity { LinearLayout rootview = null; TextView world1 = null; TextView world2 = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rootview = (LinearLayout)findViewById(R.id.rootview); FontTest.changeFont(rootview, this); // Typeface tf = null; // tf = Typeface.createFromAsset(this.getAssets(), "fonts/Arial.ttf"); // world1 = (TextView)findViewById(R.id.world1); // world2 = (TextView)findViewById(R.id.world2); // world2.setTypeface(tf); }
相关文章推荐
- Android禁止ViewPager的左右滑动
- AndroidAnnotations快速开发框架
- Android开发之实用小知识点汇总-2
- 优秀Android博客大全,整理了国内外大神博客/Github地址,是学习Android进阶的首选[转]
- Android 曾经的小Bug(常识)
- 关于Android studio创建时继承ActionBarActivity 如何修改的问题
- GitHub上史上最全的Android开源项目分类汇总
- 使用代码实现Android的清除数据的功能
- Android平台录音音量计的实现
- 【android】在Eclipse在联想引jar包源代码
- android 声明广播
- android sdk manager settings on os (mac)
- Android studio was unable to create a local connection in order...
- android实例 listview与sqlite数据绑定
- Android开发之实用小知识点汇总-1
- android 的四种枚举Context.MODE_PRIVATE ……
- Android 之一个简单计算器源代码
- bsh for android : 北京
- Android横屏竖屏设置
- android 选择本地图片并截剪图片保存到,sdcard指定目录中