我刚刚下载了Eclipse并使用ActionBarActivity
并使用sdk api 23创建了android-support-v7-appcompat
。当我尝试运行应用程序时,我得到了这个异常(错误膨胀类android.support.v7。 widget.Toolbar):
02-27 00:42:13.266: E/VdcInflateDelegate(17270): Exception while inflating <vector>
02-27 00:42:13.266: E/VdcInflateDelegate(17270): org.xmlpull.v1.XmlPullParserException: Binary XML file line #17<vector> tag requires viewportWidth > 0
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.graphics.drawable.VectorDrawableCompat.updateStateFromTypedArray(VectorDrawableCompat.java:535)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.graphics.drawable.VectorDrawableCompat.inflate(VectorDrawableCompat.java:472)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.graphics.drawable.VectorDrawableCompat.createFromXmlInner(VectorDrawableCompat.java:436)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:829)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:303)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:178)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at java.lang.reflect.Constructor.constructNative(Native Method)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at com.testing.name.MainActivity.onCreate(MainActivity.java:13)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.Activity.performCreate(Activity.java:5451)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.ActivityThread.access$900(ActivityThread.java:169)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.os.Handler.dispatchMessage(Handler.java:102)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.os.Looper.loop(Looper.java:136)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at android.app.ActivityThread.main(ActivityThread.java:5476)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at java.lang.reflect.Method.invoke(Method.java:515)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
02-27 00:42:13.266: E/VdcInflateDelegate(17270): at dalvik.system.NativeStart.main(Native Method)
02-27 00:42:13.276: E/AndroidRuntime(17270): FATAL EXCEPTION: main
02-27 00:42:13.276: E/AndroidRuntime(17270): Process: com.testing.name, PID: 17270
02-27 00:42:13.276: E/AndroidRuntime(17270): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testing.name/com.testing.name.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.ActivityThread.access$900(ActivityThread.java:169)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.os.Handler.dispatchMessage(Handler.java:102)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.os.Looper.loop(Looper.java:136)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.ActivityThread.main(ActivityThread.java:5476)
02-27 00:42:13.276: E/AndroidRuntime(17270): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 00:42:13.276: E/AndroidRuntime(17270): at java.lang.reflect.Method.invoke(Method.java:515)
02-27 00:42:13.276: E/AndroidRuntime(17270): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
02-27 00:42:13.276: E/AndroidRuntime(17270): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
02-27 00:42:13.276: E/AndroidRuntime(17270): at dalvik.system.NativeStart.main(Native Method)
02-27 00:42:13.276: E/AndroidRuntime(17270): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.createView(LayoutInflater.java:626)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:379)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:300)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:264)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
02-27 00:42:13.276: E/AndroidRuntime(17270): at com.testing.name.MainActivity.onCreate(MainActivity.java:13)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.Activity.performCreate(Activity.java:5451)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
02-27 00:42:13.276: E/AndroidRuntime(17270): ... 11 more
02-27 00:42:13.276: E/AndroidRuntime(17270): Caused by: java.lang.reflect.InvocationTargetException
02-27 00:42:13.276: E/AndroidRuntime(17270): at java.lang.reflect.Constructor.constructNative(Native Method)
02-27 00:42:13.276: E/AndroidRuntime(17270): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
02-27 00:42:13.276: E/AndroidRuntime(17270): ... 25 more
02-27 00:42:13.276: E/AndroidRuntime(17270): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020016
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.content.res.Resources.loadDrawable(Resources.java:3063)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.content.res.Resources.getDrawable(Resources.java:1624)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.TintResources.superGetDrawable(TintResources.java:48)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.AppCompatDrawableManager.onDrawableLoadedFromResources(AppCompatDrawableManager.java:374)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.TintResources.getDrawable(TintResources.java:44)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:180)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:173)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:60)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.Toolbar.<init>(Toolbar.java:254)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
02-27 00:42:13.276: E/AndroidRuntime(17270): ... 28 more
02-27 00:42:13.276: E/AndroidRuntime(17270): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
02-27 00:42:13.276: E/AndroidRuntime(17270): at android.content.res.Resources.loadDrawable(Resources.java:3059)
02-27 00:42:13.276: E/AndroidRuntime(17270): ... 38 more
这是清单中的应用程序标记,它使用操作栏的样式:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
和风格:
<?xml version="1.0" encoding="utf-8"?>
<style name="AppTheme" parent="@style/Base.Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@android:color/white</item>
<item name="background">@android:color/white</item>
<item name="android:icon">@android:color/transparent</item>
<item name="icon">@android:color/transparent</item>
<item name="titleTextStyle">@style/ActionBarTitleText</item>
<item name="subtitleTextStyle">@style/ActionBarSubTitleText</item>
</style>
<style name="ActionBarTitleText" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/bluedark</item>
<item name="android:textSize">28sp</item>
<item name="android:gravity">center</item>
</style>
<style name="ActionBarSubTitleText" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/bluedark</item>
<item name="android:textSize">35sp</item>
<item name="android:gravity">center</item>
</style>
在活动的图形布局中,我甚至看不到操作栏。 我该如何解决这个问题?
答案 0 :(得分:0)
我认为这是兼容性库中的一个错误。 (与尝试夸大兼容性布局abc_screen_toolbar.xml有关。)
使用V7库v23.2.0时,有几种方法可以解决此问题:
(按照最简单但最差的解决方案,在列表末尾提供更好但更具参与性的替代方案)
compile 'com.android.support:support-annotations:23.2.0'
不 compile 'com.android.support:support-annotations:23.2.0@aar'
(请注意@aar
的缺席通常会更好,但显然不是这种情况)ActionBar
类。 (请参阅使用AppBarLayout
android.support.v7.widget.Toolbar
并通过致电setSupportActionBar()
附加的Android指南Setting Up the App Bar。