如何设置android app 的字体大小不受系统字体大小改变的影响
2015-06-24 09:59
477 查看
从android4.0起系统设置的”显示“提供设置字体大小的选项。这个设置直接会影响到所有sp为单位的字体适配,所以很多app在设置了系统字体后瞬间变得面目全非。下面是解决方案
[java] view
plaincopyprint?
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics() );
虽然google推荐使用sp作为字体的单位,但实际的开发过程中通常是根据UIUE的设计稿来换算 sp(px换算sp)。而sp即使在同一种密度下其值也不尽相同。比如在240dpi的设备,如果是480x800分辨率这个值通常是1.5倍 (scaledDensity=1.5),如果是480xZ(z>800)那么这个值有可能大于1.5。这无疑给设备的适配带来更多的困难和陷阱。所以个人通常建议使用dpi来作为字体的单位
对于个别app不需要根据系统字体的大小来改变的,可以在activity基类(app中所有的activity都应该有继承于我们自己定义的一个BaseActivity类)中加上以下code:
[java] view
plaincopyprint?
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics() );
return res;
}
[java] view
plaincopyprint?
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics() );
虽然google推荐使用sp作为字体的单位,但实际的开发过程中通常是根据UIUE的设计稿来换算 sp(px换算sp)。而sp即使在同一种密度下其值也不尽相同。比如在240dpi的设备,如果是480x800分辨率这个值通常是1.5倍 (scaledDensity=1.5),如果是480xZ(z>800)那么这个值有可能大于1.5。这无疑给设备的适配带来更多的困难和陷阱。所以个人通常建议使用dpi来作为字体的单位
对于个别app不需要根据系统字体的大小来改变的,可以在activity基类(app中所有的activity都应该有继承于我们自己定义的一个BaseActivity类)中加上以下code:
[java] view
plaincopyprint?
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics() );
return res;
}
相关文章推荐
- Android大图片裁剪终极解决方案
- MVP模式在Android开发中的应用
- cocos2dx常见的46种+22种动作详解
- Android Memory Management, OutOfMemoryError
- 使用和管理Android中Activity的切换动画(一)
- iOS开发中的一些tips
- 产品体验分析:两款天气预报APP产品分析报告
- different services that PSAPPSRV executes and what do they do?
- android简单的点击刷新
- 关于android缩放bitmap,BitmapFactory.Options.inSampleSize的优化算法
- 九鼎创展s5p4418开发板Android4.4-如何配置内核
- 浅尝Unity 3D的Asset Bundle知识(一)
- 使用和管理Android中Activity的切换动画(二)
- 浅谈Android Fragment嵌套使用存在的一些BUG以及解决方法
- Android中自定义view出错NoSuchMethodException
- Android笔记-ListView总结
- Android jni 高斯模糊效果
- Android中实现远程输入
- android开发 获取logcat日志并记录(方便离线调试)
- Swift 2 if case 用法