修改交友布局
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.xscm.moduleutil.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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user