(Activity+preferencefragment) 膨胀 class com.android.internal.widget.ActionBarContainer 时出错
(Activity+preferencefragment) Error inflating class com.android.internal.widget.ActionBarContainer
我不知道这个错误。
我从 google 开发者控制台得到了这些信息。
z3、htc m8、m9 等设备无法执行我的应用程序。有人可以给我一些关于错误的提示吗?
堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{package name/package name.SettingsActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.access0(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:5900)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3659)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3755)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:403)
at android.app.Activity.setContentView(Activity.java:2174)
at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:553)
at pavkage name.SettingsActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5981)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1124)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2452)
... 10 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 24 more
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13
at android.content.res.TypedArray.getDrawable(TypedArray.java:747)
at android.view.View.<init>(View.java:3785)
at android.view.ViewGroup.<init>(ViewGroup.java:513)
at android.widget.FrameLayout.<init>(FrameLayout.java:128)
at android.widget.FrameLayout.<init>(FrameLayout.java:124)
at android.widget.FrameLayout.<init>(FrameLayout.java:119)
at com.android.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:61)
... 27 more
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="package name.SettingsActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.AppBarOverlay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_general_category">
<SeekBarPreference
android:defaultValue="10"
android:key="@string/PrefResetWhistleIntervalKey"
android:summary="@string/pref_reset_whistle_interval"
android:title="@string/pref_title_reset_whistle_interval"/>
<SeekBarPreference
android:defaultValue="10"
android:key="@string/PrefWhistleAmountKey"
android:summary="@string/pref_whistle_count"
android:title="@string/pref_title_whistle_count"/>
<SeekBarPreference
android:key="@string/PrefVolumeKey"
android:summary="@string/pref_alarm_volume"
android:title="@string/pref_title_alarm_volume"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/PrefMediaPlayerLoopKey"
android:summary="@string/pref_mediaplay_loop"
android:title="@string/pref_title_mediaplay_loop"/>
<Preference
android:clickable="false"
android:editable="false"
android:enabled="true"
android:key="@string/PrefChooseAudioKey"
android:selectable="true"
android:summary=""
android:title="@string/pref_title_choose_media"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_battery_save_category">
<ListPreference
android:defaultValue="@string/pref_sensitivity_default_value"
android:dialogTitle="@string/pref_title_sensitivity"
android:entries="@array/array_sensitivity_item"
android:entryValues="@array/array_sensitivity_value"
android:key="@string/PrefSensitivityKey"
android:summary="@string/pref_sensitivity"
android:title="@string/pref_title_sensitivity"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_system_category">
<SwitchPreference
android:defaultValue="true"
android:key="@string/PrefEnableServiceKey"
android:summary="@string/pref_service_on_off"
android:title="@string/pref_title_service_on_off"/>
<SwitchPreference
android:defaultValue="true"
android:key="@string/PrefEnableBootServiceKey"
android:summary="@string/pref_start_service_ono_ff"
android:title="@string/pref_title_start_service_on_off"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/testMode">
<Preference
android:clickable="false"
android:editable="false"
android:enabled="true"
android:key="@string/PrefTestModeKey"
android:selectable="true"
android:summary="@string/pref_test_mode"
android:title="@string/pref_title_test_mode"/>
</PreferenceCategory>
</PreferenceScreen>
seekbarpreference 取自
http://robobunny.com/blog_files/android_seekbar_preference/SeekBarPreference.java
我有同样的错误,这是我的处理方式。
在 styles.xml 文件中,第一个 "AppTheme" 样式将 Base 放在 Theme.AppCompat 的前面。所以它将是 "Base.Theme.AppCompat.Light.DarkActionBar".
之后,转到您的 "AndroidManifest",在您的 activity 中不要使用 "AppBarOverlay"。所以它只是 "android:theme="@style/AppTheme".
此外,在 "AndroidManifest" 中从您的 activity 名称中删除 "package name",然后只使用“.SettingsActivity”。
如果您有其他活动,则无需在每个 activity 中定义 AppTheme,只需使用 android:parentActivityName=".SettingsActivity."
我知道您想要一个操作栏,删除 AppBarOverlay 可能会有所帮助。
让我知道它是否有效。
用 AppCompatActivity 扩展 class 而不是 Activity 它会给你操作栏
我不知道这个错误。 我从 google 开发者控制台得到了这些信息。 z3、htc m8、m9 等设备无法执行我的应用程序。有人可以给我一些关于错误的提示吗?
堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{package name/package name.SettingsActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.access0(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:5900)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3659)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3755)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:403)
at android.app.Activity.setContentView(Activity.java:2174)
at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:553)
at pavkage name.SettingsActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5981)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1124)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2452)
... 10 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 24 more
Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 13
at android.content.res.TypedArray.getDrawable(TypedArray.java:747)
at android.view.View.<init>(View.java:3785)
at android.view.ViewGroup.<init>(ViewGroup.java:513)
at android.widget.FrameLayout.<init>(FrameLayout.java:128)
at android.widget.FrameLayout.<init>(FrameLayout.java:124)
at android.widget.FrameLayout.<init>(FrameLayout.java:119)
at com.android.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:61)
... 27 more
styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="package name.SettingsActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:theme="@style/AppTheme.AppBarOverlay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_general_category">
<SeekBarPreference
android:defaultValue="10"
android:key="@string/PrefResetWhistleIntervalKey"
android:summary="@string/pref_reset_whistle_interval"
android:title="@string/pref_title_reset_whistle_interval"/>
<SeekBarPreference
android:defaultValue="10"
android:key="@string/PrefWhistleAmountKey"
android:summary="@string/pref_whistle_count"
android:title="@string/pref_title_whistle_count"/>
<SeekBarPreference
android:key="@string/PrefVolumeKey"
android:summary="@string/pref_alarm_volume"
android:title="@string/pref_title_alarm_volume"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/PrefMediaPlayerLoopKey"
android:summary="@string/pref_mediaplay_loop"
android:title="@string/pref_title_mediaplay_loop"/>
<Preference
android:clickable="false"
android:editable="false"
android:enabled="true"
android:key="@string/PrefChooseAudioKey"
android:selectable="true"
android:summary=""
android:title="@string/pref_title_choose_media"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_battery_save_category">
<ListPreference
android:defaultValue="@string/pref_sensitivity_default_value"
android:dialogTitle="@string/pref_title_sensitivity"
android:entries="@array/array_sensitivity_item"
android:entryValues="@array/array_sensitivity_value"
android:key="@string/PrefSensitivityKey"
android:summary="@string/pref_sensitivity"
android:title="@string/pref_title_sensitivity"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_system_category">
<SwitchPreference
android:defaultValue="true"
android:key="@string/PrefEnableServiceKey"
android:summary="@string/pref_service_on_off"
android:title="@string/pref_title_service_on_off"/>
<SwitchPreference
android:defaultValue="true"
android:key="@string/PrefEnableBootServiceKey"
android:summary="@string/pref_start_service_ono_ff"
android:title="@string/pref_title_start_service_on_off"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/testMode">
<Preference
android:clickable="false"
android:editable="false"
android:enabled="true"
android:key="@string/PrefTestModeKey"
android:selectable="true"
android:summary="@string/pref_test_mode"
android:title="@string/pref_title_test_mode"/>
</PreferenceCategory>
</PreferenceScreen>
seekbarpreference 取自 http://robobunny.com/blog_files/android_seekbar_preference/SeekBarPreference.java
我有同样的错误,这是我的处理方式。 在 styles.xml 文件中,第一个 "AppTheme" 样式将 Base 放在 Theme.AppCompat 的前面。所以它将是 "Base.Theme.AppCompat.Light.DarkActionBar".
之后,转到您的 "AndroidManifest",在您的 activity 中不要使用 "AppBarOverlay"。所以它只是 "android:theme="@style/AppTheme".
此外,在 "AndroidManifest" 中从您的 activity 名称中删除 "package name",然后只使用“.SettingsActivity”。
如果您有其他活动,则无需在每个 activity 中定义 AppTheme,只需使用 android:parentActivityName=".SettingsActivity."
我知道您想要一个操作栏,删除 AppBarOverlay 可能会有所帮助。 让我知道它是否有效。
用 AppCompatActivity 扩展 class 而不是 Activity 它会给你操作栏