項目中遇到一個問題,在設置中更改系統字體為特大,再次進入App已經變的面目全非了,各種顯示的問題。
各種google之后,在starkoverflow找到的答案:
在BaseActivity中調用
private void initFontScale() {
Configuration configuration = getResources().getConfiguration();
configuration.fontScale = (float) 1;
//0.85 小, 1 標準大小, 1.15 大,1.3 超大 ,1.45 特大
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
metrics.scaledDensity = configuration.fontScale * metrics.density;
getBaseContext().getResources().updateConfiguration(configuration, metrics);
}
系統定制更改字體大小主要是通過更改屬性 fontScale 來實現的
只要我們在App中 顯示的設置一個 fontScale 無論怎樣在設置中修改字體大小都不會影響到App中的字體大小。
(ps:dialog popupwindow 除外,這兩種需要在控件中重新設置fontScale)