gpt4 book ai didi

android - RuntimeException 无法启动 Activity .. InflateException 二进制 XML 行 #37 : Error inflating class com. android.internal.widget.ActionBarView

转载 作者:太空狗 更新时间:2023-10-29 14:58:48 25 4
gpt4 key购买 nike

当我将主题添加到 Activity 时,应用程序在使用以下 logcat 打开该 Activity 后崩溃

 FATAL EXCEPTION: main
Process: com.jd.activity, PID: 16672
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jd.activity/com.jd.activity.AlertActivity}: android.view.InflateException: Binary XML file line #37: Error inflating class com.android.internal.widget.ActionBarView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5479)
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:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class com.android.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3296)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3359)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:362)
at android.app.Activity.setContentView(Activity.java:2031)
at com.jd.activity.AlertActivity.onCreate(AlertActivity.java:59)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
... 25 more
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.android.internal.widget.ActionBarView.initTitle(ActionBarView.java:1200)
at com.android.internal.widget.ActionBarView.setDisplayOptions(ActionBarView.java:982)
at com.android.internal.widget.ActionBarView.<init>(ActionBarView.java:398)
... 28 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
... 37 more
Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
at android.content.res.TypedArray.getColor(TypedArray.java:327)
at android.widget.TextView.<init>(TextView.java:1003)
at android.widget.TextView.<init>(TextView.java:908)
... 40 more

我在 list 中的 Activity 标签

<activity
android:name="com.jd.activity.AlertActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Base.TextAppearance.AppCompat"
android:windowSoftInputMode="stateHidden|adjustPan" >
</activity>

即使应用程序在添加主题后崩溃

 android:theme="@style/MyTheme.ActionBar.TitleTextStyle"

当我删除主题行时,效果很好。

我已经添加了 android-support-v7-appcompat到项目的构建路径和我从 sdk\extras\android\v7 导入的那个应用程序,勾选了“将项目复制到工作区”。

也在 list 中 <uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />

我的最终目标是添加 ActionBar。有没有其他简单的方法可以在不使用主题的情况下添加操作栏?

最佳答案

我通过创建自己的主题解决了这个问题

<style name="MyTheme" parent="@android:style/Theme.Holo">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item>
<item name="android:windowBackground">@color/gray</item>
<item name="android:colorBackground">@color/gray</item>
<item name="android:actionButtonStyle">@style/ActionButtonStyle</item>
<item name="android:actionModeCloseButtonStyle">@style/CloseButton</item>
<item name="android:actionModeBackground">@drawable/action_bar_inset_backgruond</item>
<item name="contentInsetLeft">10dp</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:icon">@android:color/transparent</item>
<item name="android:background">@color/black_tint_80</item>
<item name="android:titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
<item name="android:actionOverflowButtonStyle">@style/OverflowMenuButton</item>
<item name="android:actionButtonStyle">@style/ActionButtonStyle</item>
<item name="android:actionModeCloseButtonStyle">@style/CloseButton</item>
<item name="android:actionModeBackground">@drawable/action_bar_inset_backgruond</item>
<item name="android:logo">@drawable/actionbar_space_between_icon_and_title</item>
<item name="contentInsetLeft">10dp</item>
</style>

<style name="AppTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.StatusBar.Title">
<item name="android:textColor">@color/white</item>
<item name="android:textSize">20sp</item>
<item name="android:gravity">center</item>
<item name="android:paddingLeft">100dp</item>
<item name="android:actionButtonStyle">@style/ActionButtonStyle</item>
</style>

<style name="OverflowMenuButton" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">@drawable/ic_action_view_as_grid</item>
</style>

<style name="ActionButtonStyle" parent="@android:style/Widget.Holo.Light.ActionButton">
<item name="android:minWidth">100dip</item>
<item name="android:paddingLeft">100dip</item>
<item name="android:paddingRight">100dip</item>
</style>

<style name="CloseButton" parent="@android:style/Widget.Holo.ActionButton.CloseMode">
<item name="android:background">@drawable/ic_action_view_as_grid</item>
</style>

并在 manifest.xml 中应用它

android:theme="@style/MyTheme" 

而且,在执行此操作时,无需从 ActionBarActivity

进行扩展

关于android - RuntimeException 无法启动 Activity .. InflateException 二进制 XML 行 #37 : Error inflating class com. android.internal.widget.ActionBarView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28878219/

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