Android 兼容8.0及以上 App全局字体调节、禁止App字体随系统字体大小而更改
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 兼容8.0及以上 App全局字体调节、禁止App字体随系统字体大小而更改相关的知识,希望对你有一定的参考价值。
参考技术A 在APP中,字体的大小单位一般会用sp,然而在改变系统字体大小时,App字体就会随着系统字体大小改变而改变,这就可能造成APP布局的错位。造成这种情况的原因是,sp单位除了受屏幕密度影响外,还受到用户的字体大小影响,通常情况下,建议使用sp来跟随用户字体大小设置。除非一些特殊的情况,不想跟随系统字体变化的,可以使用dp”。按照这么说,布局宽高固定写死的地方应该统一用dp显示字体,因为一旦用户在设置中调大字体,宽高写死的布局显示就乱了。
针对这种情况,查找网上的方法也很多,大多是这样的方法 (重写 Application 或 BaseActivity 中的方法):
如何有更好的方案,请给与连接或说明
我的Android App 支持7.0及以上版本但不支持6和5
【中文标题】我的Android App 支持7.0及以上版本但不支持6和5【英文标题】:My Android App support in version 7.0 and upper version but not support version 6 and 5 【发布时间】:2020-03-27 17:13:03 【问题描述】:其实我不知道是什么问题。我试过但不明白确切的问题!
compileSdkVersion 28,
minSdkVersion 21,
targetSdkVersion 28.
此问题仅在 android 版本 6 和 5 中出现。但我的应用在 android 7.0 及更高版本中正常运行。
这里是 Logcat 错误消息
12-03 09:23:44.932 6025-6025/? I/art: Not late-enabling -Xcheck:jni (already on) 12-03 09:23:45.029 6025-6025/io.destreza.erp_dashboard W/System: ClassLoader referenced unknown path: /data/app/io.destreza.erp_dashboard-1/lib/x86 12-03 09:23:45.075 6025-6025/io.destreza.erp_dashboard D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization. 12-03 09:23:45.076 6025-6025/io.destreza.erp_dashboard D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization. 12-03 09:23:45.076 6025-6025/io.destreza.erp_dashboard D/FirebaseApp: com.google.android.gms.measurement.AppMeasurement is not linked. Skipping initialization. 12-03 09:23:45.076 6025-6025/io.destreza.erp_dashboard I/FirebaseInitProvider: FirebaseApp initialization successful 12-03 09:23:45.116 6025-6025/io.destreza.erp_dashboard W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable 12-03 09:23:45.149 6025-6025/io.destreza.erp_dashboard I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper> 12-03 09:23:45.149 6025-6025/io.destreza.erp_dashboard I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper> 12-03 09:23:45.194 6025-6025/io.destreza.erp_dashboard W/ResourceType: Failure getting entry for 0x7f07009e (t=6 e=158) (error -75) 12-03 09:23:45.195 6025-6025/io.destreza.erp_dashboard D/AndroidRuntime: Shutting down VM 12-03 09:23:45.196 6025-6025/io.destreza.erp_dashboard E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.destreza.erp_dashboard, PID: 6025
java.lang.RuntimeException: Unable to start activity ComponentInfoio.destreza.erp_dashboard/io.destreza.erp_dashboard.activities.main.MainActivity: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class ImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at io.destreza.erp_dashboard.activities.main.MainActivity.onCreate(MainActivity.java:115)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at io.destreza.erp_dashboard.activities.main.MainActivity.onCreate(MainActivity.java:115)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.res.Resources$NotFoundException: Resource "io.destreza.erp_dashboard:drawable/logo_main" (7f07009e) is not a Drawable (color or path): TypedValuet=0x1/d=0x7f07009e a=-1 r=0x7f07009e
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2602)
at android.content.res.Resources.loadDrawable(Resources.java:2540)
at android.content.res.TypedArray.getDrawable(TypedArray.java:870)
at android.view.View.<init>(View.java:3948)
at android.widget.ImageView.<init>(ImageView.java:145)
at android.widget.ImageView.<init>(ImageView.java:140)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at io.destreza.erp_dashboard.activities.main.MainActivity.onCreate(MainActivity.java:115)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 12-03 09:24:15.098 6025-6044/io.destreza.erp_dashboard E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE 12-03 09:25:15.188 6025-6044/io.destreza.erp_dashboard E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE 12-03 09:26:45.255 6025-6044/io.destreza.erp_dashboard E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE 12-03 09:28:45.594 6025-6025/io.destreza.erp_dashboard I/Process: Sending signal. PID: 6025 SIG: 9 [app has been stoped!][1]
Screenshot-The app has been stopped!
【问题讨论】:
【参考方案1】:检查您的资源和其他人,当他们在应用程序将无法运行的更高版本文件夹中时。
【讨论】:
【参考方案2】:FATAL EXCEPTION: main Process: io.destreza.erp_dashboard, PID: 6025 java.lang.RuntimeException: Unable to start activity ComponentInfoio.destreza.erp_dashboard/io.destreza.erp_dashboard.activities.main.MainActivity: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class ImageView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at
这就是问题在于尝试查找是否可以找到资源。如果它被找到但它是矢量图像,那么它可能会崩溃,因为某些矢量图像在旧的 android 版本中无法正常工作,也许可以尝试用 png 图像更改它
【讨论】:
我终于解决了!基本上这不是图像类型问题。我用 android:src="@drawable/logo_main" 代替 android:background="@drawable/logo_main" 谢谢 Nikhil以上是关于Android 兼容8.0及以上 App全局字体调节、禁止App字体随系统字体大小而更改的主要内容,如果未能解决你的问题,请参考以下文章
根据状态栏颜色亮度设置黑白字体(Android 6.0及以上版本)