android-使用Widget.Sherlock.ActionButton使ImageView膨胀时,资源不是可绘制的
作者:互联网
嗨,我正在尝试向操作栏添加动画视图,但是在Android 2.3上出现此错误(在Android 4上有效)
1194 AndroidRuntime E FATAL EXCEPTION: main
1194 AndroidRuntime E android.view.InflateException: Binary XML file line #3: Error inflating class <unknown>
1194 AndroidRuntime E at android.view.LayoutInflater.createView(LayoutInflater.java:518)
1194 AndroidRuntime E at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
1194 AndroidRuntime E at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
1194 AndroidRuntime E at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
1194 AndroidRuntime E at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
1194 AndroidRuntime E at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
1194 AndroidRuntime E at it.patrick91.unisamenu.MainActivity.load(MainActivity.java:165)
1194 AndroidRuntime E at it.patrick91.unisamenu.MainActivity.onOptionsItemSelected(MainActivity.java:219)
1194 AndroidRuntime E at com.actionbarsherlock.app.SherlockListActivity.onMenuItemSelected(SherlockListActivity.java:208)
1194 AndroidRuntime E at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:603)
1194 AndroidRuntime E at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:529)
1194 AndroidRuntime E at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
1194 AndroidRuntime E at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
1194 AndroidRuntime E at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
1194 AndroidRuntime E at com.actionbarsherlock.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:510)
1194 AndroidRuntime E at com.actionbarsherlock.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:145)
1194 AndroidRuntime E at android.view.View.performClick(View.java:2485)
1194 AndroidRuntime E at android.view.View$PerformClick.run(View.java:9080)
1194 AndroidRuntime E at android.os.Handler.handleCallback(Handler.java:587)
1194 AndroidRuntime E at android.os.Handler.dispatchMessage(Handler.java:92)
1194 AndroidRuntime E at android.os.Looper.loop(Looper.java:130)
1194 AndroidRuntime E at android.app.ActivityThread.main(ActivityThread.java:3687)
1194 AndroidRuntime E at java.lang.reflect.Method.invokeNative(Native Method)
1194 AndroidRuntime E at java.lang.reflect.Method.invoke(Method.java:507)
1194 AndroidRuntime E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
1194 AndroidRuntime E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
1194 AndroidRuntime E at dalvik.system.NativeStart.main(Native Method)
1194 AndroidRuntime E Caused by: java.lang.reflect.InvocationTargetException
1194 AndroidRuntime E at java.lang.reflect.Constructor.constructNative(Native Method)
1194 AndroidRuntime E at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
1194 AndroidRuntime E at android.view.LayoutInflater.createView(LayoutInflater.java:505)
1194 AndroidRuntime E ... 26 more
1194 AndroidRuntime E Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000f a=3}
1194 AndroidRuntime E at android.content.res.Resources.loadDrawable(Resources.java:1681)
1194 AndroidRuntime E at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
1194 AndroidRuntime E at android.view.View.<init>(View.java:1951)
1194 AndroidRuntime E at android.widget.ImageView.<init>(ImageView.java:112)
1194 AndroidRuntime E at android.widget.ImageView.<init>(ImageView.java:108)
1194 AndroidRuntime E ... 29 more
使图像膨胀的代码是这样的:
LayoutInflater inflater = (LayoutInflater) getApplication()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView iv = (ImageView) inflater.inflate(R.layout.load_action_view,
null);
Animation rotation = AnimationUtils.loadAnimation(getApplication(),
R.anim.load_anim);
rotation.setRepeatCount(Animation.INFINITE);
iv.startAnimation(rotation);
load_action_view.xml是这样的:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.Sherlock.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_load" />
做一些测试,我注意到删除style =“ @ style / Widget.Sherlock.ActionButton”可以解决此问题.
我在清单中的应用程序标签是这样的:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >..</application>
你知道是什么问题吗?
解决方法:
修复了将getApplication()更改为此(它在Activity中)的问题
标签:actionbarsherlock,android 来源: https://codeday.me/bug/20191031/1976593.html