本文所涉及的都方法需要依赖系统源码,内置系统应用,仅此记录一下
一、修改字体大小:
private float[] mFontValues = {0.85f, 1.0f, 1.15f, 1.30f};
final ContentResolver resolver = getContentResolver();
Settings.System.putFloat(resolver, Settings.System.FONT_SCALE, mFontValues[progress]);
二、修改显示大小:
import android.view.Display;
import com.android.settingslib.display.DisplayDensityUtils;
private void doInitDpi() {
final DisplayDensityUtils density = new DisplayDensityUtils(getApplicationContext());
final int initialIndex = density.getCurrentIndex();
if (initialIndex < 0) {
final int densityDpi = getResources().getDisplayMetrics().densityDpi;
mValues = new int[]{densityDpi};
mDefaultDensity = densityDpi;
} else {
mValues = density.getValues();
mDefaultDensity = density.getDefaultDensity();
}
for (int i = 0; i < mValues.length; i++) {
Log.d(TAG, "doInitDpi: mValues[" + i + "] = " + mValues[i]);
}
Log.d(TAG, "doInitDpi: mDefaultDensity = " + mDefaultDensity);
}
DisplayDensityUtils.setForcedDisplayDensity(Display.DEFAULT_DISPLAY, densityDpi);
三、修改默认dpi
private void doCustomDpi(int inputDpi) {
final Resources res = getResources();
final DisplayMetrics metrics = res.getDisplayMetrics();
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
final int newSwDp = Math.max(inputDpi, 320);
final int minDimensionPx = Math.min(metrics.widthPixels, metrics.heightPixels);
final int newDensity = DisplayMetrics.DENSITY_MEDIUM * minDimensionPx / newSwDp;
final int densityDpi = Math.max(newDensity, 120);
Log.d(TAG, "doCustomDpi: inputDpi = " + inputDpi + ", newSwDp = " + +newSwDp + ", minDimensionPx = " + minDimensionPx
+ ", newDensity = " + newDensity + ", densityDpi = " + densityDpi);
DisplayDensityUtils.setForcedDisplayDensity(Display.DEFAULT_DISPLAY, densityDpi);
}
源码地址:https://download.csdn.net/download/hj_key/12532653
转载请标明出处:https://blog.csdn.net/hj_key/article/details/106836256