如何以编程方式更改设备的字体设置:字体样式和字体大小? [英] How to programmatically change font settings of Device: font style and font size?

查看:513
本文介绍了如何以编程方式更改设备的字体设置:字体样式和字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何改变字体和字体大小以编程方式?我不是指改变一个TextView或EDITTEXT的字体样式。

How do we change font type and font size programmatically? I am not referring to changing the font style of a textview or editText.

我想改变的全局字体设置,就在我的应用程序点击一个按钮的字体类型和字体大小之间切换。我试图检查 Settings.System 属性,但是我无法找到他们。任何想法?

I want to change the global font settings, toggling between font types and font sizes on a button click in my app. I tried checking the Settings.System attributes but I could not find them. Any ideas?

推荐答案

您可以使用下面code更改系统字体

You can change system font using below code

Settings.System.putFloat(getBaseContext().getContentResolver(),
            Settings.System.FONT_SCALE, (float) 1.0);

和在menifest文件这个授予权限后

and after this give permission in menifest file

  <uses-permission android:name="android.permission.WRITE_SETTINGS"/>

,然后重新启动设备显示效果。

and then restart your device to show effect..

请注意:它完全适用于根装置和设备无根某些字体可能会改变,有些则不是。

Note: Its fully applicable for rooted device and in Unrooted device some font may change and some are not.

这篇关于如何以编程方式更改设备的字体设置:字体样式和字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆