Blankj / AndroidUtilCode

:fire: Android developers should collect the following utils(updating).
https://blankj.com/2016/07/31/android-utils-code/
Apache License 2.0
33.24k stars 10.67k forks source link

ToastUtils能不依赖V4包吗? #331

Closed Android-xiaole closed 6 years ago

Android-xiaole commented 6 years ago

我在使用:ToastUtils.showShort("aa");的时候报如下错误 java.lang.NoClassDefFoundError: android.support.v4.widget.TextViewCompat at com.blankj.utilcode.util.ToastUtils$1.run(ToastUtils.java:214) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5291) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) at dalvik.system.NativeStart.main(Native Method)

查看了你的源码: private static void show(final CharSequence text, final int duration) { HANDLER.post(new Runnable() { @Override public void run() { cancel(); sToast = Toast.makeText(Utils.getApp(), text, duration); // solve the font of toast TextView tvMessage = (TextView) sToast.getView().findViewById(android.R.id.message); TextViewCompat.setTextAppearance(tvMessage, android.R.style.TextAppearance); tvMessage.setTextColor(msgColor); setBgAndGravity(); sToast.show(); } }); } 由于我的项目没有依赖v4和V7jar包,也不想依赖这些jar包,建议不设置textview的兼容,这样会不会让你的项目兼容性更好呢?

Blankj commented 6 years ago

现在还有不依赖 v4 或 v7 的项目?那你要那样的话你把 ToastUtils 拷贝出去,把 TextViewCompat 那行换掉就行了,不依赖 v4 或 v7,那我这个工具类也可以不依赖,拷贝类即可。