getActionBar()SDK更新5.0后返回nullSDK、getActionBar、null

2023-09-12 02:42:16 作者:化身孤岛的蓝鲸

在我更新了Android的SDK 5.0版getActionBar()方法开始返回null导致我的应用程序崩溃上推出。我无言以对,以什么导致这一点,任何现有的#1线并没有帮助。

After I updated the Android SDK to version 5.0 the getActionBar() method started to return null causing my app to crash on launch. I am clueless to what's causing this and any existing Stackoverflow threads didn't help.

下面是我的清单:

<application
    android:name="App"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/ActionBarTheme" >

styles.xml:

styles.xml:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light"></style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme"></style>
<style name="ListItemPadding">
    <item name="android:paddingTop">8dp</item>
    <item name="android:paddingRight">5dp</item>
    <item name="android:paddingBottom">8dp</item>
    <item name="android:paddingLeft">5dp</item>
</style>

的themes.xml:

themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!-- the theme applied to the application or activity -->
<style name="ActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="android:actionOverflowButtonStyle">@style/OverflowButton</item>
    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/ActionBar</item>
    <item name="actionOverflowButtonStyle">@style/OverflowButton</item>
</style>

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

<!-- ActionBar styles -->
<style name="ActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/main</item>

    <!-- Support library compatibility -->
    <item name="background">@color/main</item>
</style>

</resources>

和我的摇篮依赖关系:

dependencies {
compile 'com.github.jenzz.undobar:library:1.1:api8Release@aar'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.loopj.android:android-async-http:1.4.5'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.google.android.gms:play-services:6.1.+'
}

任何帮助是极大AP preciated!

Any help is greatly appreciated!

推荐答案

使用 getSupportActionBar()当您使用 ActionBarActivity appcompat-V7 ,因为你似乎是在这里做什么。

Use getSupportActionBar() when you are using ActionBarActivity and appcompat-v7, as you appear to be doing here.