項(xiàng)目中遇到一個(gè)問(wèn)題,在設(shè)置中更改系統(tǒng)字體為特大,再次進(jìn)入App已經(jīng)變的面目全非了,各種顯示的問(wèn)題。
各種google之后,在starkoverflow找到的答案:
在BaseActivity中調(diào)用
private void initFontScale() {
Configuration configuration = getResources().getConfiguration();
configuration.fontScale = (float) 1;
//0.85 小, 1 標(biāo)準(zhǔn)大小, 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);
}
系統(tǒng)定制更改字體大小主要是通過(guò)更改屬性 fontScale 來(lái)實(shí)現(xiàn)的
只要我們?cè)贏(yíng)pp中 顯示的設(shè)置一個(gè) fontScale 無(wú)論怎樣在設(shè)置中修改字體大小都不會(huì)影響到App中的字體大小。
(ps:dialog popupwindow 除外,這兩種需要在控件中重新設(shè)置fontScale)