Commit 42a6e5a4 authored by maxiaoliang's avatar maxiaoliang

修改适配

parent f90e1190
...@@ -110,12 +110,12 @@ ...@@ -110,12 +110,12 @@
<!-- <meta-data--> <!-- <meta-data-->
<!-- android:name="design_height_in_dp"--> <!-- android:name="design_height_in_dp"-->
<!-- android:value="740"/>--> <!-- android:value="740"/>-->
<meta-data <!-- <meta-data-->
android:name="design_width_in_dp" <!-- android:name="design_width_in_dp"-->
android:value="360"/> <!-- android:value="360"/>-->
<meta-data <!-- <meta-data-->
android:name="design_height_in_dp" <!-- android:name="design_height_in_dp"-->
android:value="640"/> <!-- android:value="640"/>-->
</application> </application>
</manifest> </manifest>
\ No newline at end of file
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