Quellcode durchsuchen

[修改]修改字体不跟随系统设置变化

zeki vor 5 Jahren
Ursprung
Commit
db5fb2c558

BIN
app/libs/lygamewrapper-sheep-release.aar


+ 21 - 0
app/src/main/java/com/sheep/gamegroup/absBase/BaseActivity.java

@@ -1,5 +1,7 @@
 package com.sheep.gamegroup.absBase;
 
+import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.graphics.Color;
 import android.os.Build;
 import android.os.Bundle;
@@ -116,6 +118,25 @@ public abstract class BaseActivity extends RxAppCompatActivity implements BackHa
             EventBus.getDefault().register(this);
         initSlidr();
     }
+
+    @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;
+    }
+
     protected boolean showWhiteStatusBar(){return false;}
     protected int getTitleLayoutId(){
         return R.layout.title;

+ 23 - 0
app/src/main/java/com/sheep/jiuyan/samllsheep/SheepApp.java

@@ -3,6 +3,8 @@ package com.sheep.jiuyan.samllsheep;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.res.Configuration;
+import android.content.res.Resources;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -222,6 +224,27 @@ public class SheepApp extends MultiDexApplication {
 
     }
 
+
+    //设置字体为默认大小,不随系统字体大小改而改变
+    @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;
+    }
+
     /**
      * 为webView设置目录后缀
      *

+ 0 - 2
app/src/main/res/layout/act_my_money.xml

@@ -302,8 +302,6 @@
                         android:id="@+id/pager"
                         android:background="#f5f5f5"
                         android:minHeight="200dp"
-                        android:paddingStart="16dp"
-                        android:paddingEnd="16dp"
                         android:layout_width="match_parent"
                         android:layout_height="0dip"
                         android:layout_weight="1"/>