1、显示大小

    public static int getDefaultDisplayDensity(int displayId) {
        try {
            final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            return wm.getInitialDisplayDensity(displayId);
        } catch (RemoteException exc) {
            return -1;
        }
    }

    public static void setDefaultDisplay(Context context) {
        if(Build.VERSION.SDK_INT > 23) {
            Configuration origConfig = context.getResources().getConfiguration();
            origConfig.densityDpi = getDefaultDisplayDensity(Display.DEFAULT_DISPLAY);//获取手机出厂时默认的densityDpi
            context.getResources().updateConfiguration(origConfig, context.getResources().getDisplayMetrics());
        }
    }
 

在界面onCreate中调用setDefaultDisplay,强制修改分辨率

2、字体大小

   @Override
    public void onConfigurationChanged(Configuration newConfig) {
        //非默认值
        if (newConfig.fontScale != 1){
            getResources();
        }
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {//还原字体大小
        Resources res = super.getResources();
        //非默认值
        if (res.getConfiguration().fontScale != 1) {
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }

或者在xml布局中将字体修改为dp而不是用sp

更多相关文章

  1. Android6.0 Launcher3 修改app字体大小
  2. Android Studio NDK开发在C代码中将Log输出到logcat上面
  3. android Edittext内容字体大小动态变化
  4. Android 同个TextView设置字体大小不一样
  5. 调整recovery界面菜单字体大小
  6. Android getDimensionPixelSize, 代码中设置字体大小,读xml配置。
  7. Android中将Activity转换成View使用.
  8. Android 单独控件实现不同字体大小、不同颜色
  9. Android 中将 "base64图片" 解码为".png"图片

随机推荐

  1. 一,创建你的第一个Android项目
  2. 谷歌透漏开发Fuchsia的真正意图,取代Andro
  3. 简单新闻客户端APP设计
  4. Android核心分析 之一分析方法论探讨之设
  5. android v7兼容包RecyclerView的使用(三)—
  6. 二、Android(安卓)数据链接的动态分析
  7. Android(安卓)Touch事件传递
  8. android快速入门指南
  9. No cached version of androidx.appcompa
  10. android 的AIDL学习