Commit 30f61424 authored by maxiaoliang's avatar maxiaoliang

修改适配

parent 0b04c2aa
package com.zxhl.cms.utils;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
public class DisplayUtil {
/**
* 保持字体大小不随系统设置变化(用在界面加载之前)
* 要重写Activity的attachBaseContext()
*/
public static Context attachBaseContext(Context context, float fontScale) {
Configuration config = context.getResources().getConfiguration();
//正确写法
config.fontScale = fontScale;
return context.createConfigurationContext(config);
}
/**
* 保持字体大小不随系统设置变化(用在界面加载之前)
* 要重写Activity的getResources()
*/
public static Resources getResources(Context context, Resources resources, float fontScale) {
Configuration config = resources.getConfiguration();
if(config.fontScale != fontScale) {
config.fontScale = fontScale;
return context.createConfigurationContext(config).getResources();
} else {
return resources;
}
}
/**
* 保存字体大小,后通知界面重建,它会触发attachBaseContext,来改变字号
*/
public static void recreate(Activity activity) {
activity.recreate();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment