lpares12
lpares12

Reputation: 4013

Actionbar not appearing Android Studio

I made a project in Android Studio with one of my classmates. The problem is that he added a style and it disappeared. We need to add it again, but we've been trying and couldn't manage to do it (it's our first time using android).

Our AndroidManifest has this:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name="iuAndroid.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

And in our styles.xml file we have this:

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowActionBar">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

I've tried to add android:theme="@style/AppTheme.AppBarOverlay" inside the activity parameters but it crashes when calling setContentView(R.layout.activity_main);. With this error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{packet.iuandroid/iuAndroid.MainActivity}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer

Has anyone had the same problem?

Thanks!

Edit: forgot to add that the API I'm using is the 23.

Upvotes: 0

Views: 1952

Answers (2)

frogatto
frogatto

Reputation: 29287

Your styles are fine and don't cause the action bar to hide. Make sure your MainActivity is inheriting AppCompactActivity.

Also there's no need to the following item, you can remove it.

<item name="android:windowActionBar">true</item>

Upvotes: 0

Roman Svitukha
Roman Svitukha

Reputation: 1402

Try setHasOptionsMenu(true); in your Java code.

Upvotes: 1

Related Questions