How to programmatically change font settings of Device: font style and font size?

帅比萌擦擦* 提交于 2019-12-20 05:03:34

问题


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

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?


回答1:


You can change system font using below code

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

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.




回答2:


You can use FONT_SCALE from android.provider.Settings.System.

and also see this.

Read font size from Settings

Hope this might help you.



来源:https://stackoverflow.com/questions/23421676/how-to-programmatically-change-font-settings-of-device-font-style-and-font-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!