gpt4 book ai didi

android - 使用 Widget.Sherlock.ActionButton 膨胀 ImageView 时资源不是 Drawable

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:42 25 4
gpt4 key购买 nike

您好,我正在尝试向操作栏添加动画 View ,但我在 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"可以解决问题。

我在 list 中的应用程序标签是这样的:

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sherlock" >..</application>

你知道问题出在哪里吗?

最佳答案

修复了将 getApplication() 更改为此(它在 Activity 中)

关于android - 使用 Widget.Sherlock.ActionButton 膨胀 ImageView 时资源不是 Drawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13734716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com