Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Action Bar Missing

I promise this isn't a duplicate question. I've seen a bunch of other questions on this topic that are similar but they all seem to be using appCompat, and none answer my question.

The Problem

I'm running into a problem where I can't get the actionbar to show if I use the Material theme Theme.Material.Light compiling against the v21 APIs in AOSP. Everything shows up very material looking but there's no actionbar.

What I've Tried

  • I had the app output Build.VERSION.SDK_INT and Build.VERSION.RELEASE. The results were as 21 and 5.0.1 respectively as expected.
  • I switched to using a different themes. Theme.Material.Light.DarkActionBar didn't have an actionbar. Theme.Material.NoActionBar showed a smaller dialog-like window of my app without an actionbar but with a top title bar. Theme.Holo.Light shows an actionbar but it gives me all the Holo theme icons and animations.
  • I tried getting the actionbar programmatically with getActionBar().show(); but got a null pointer exception.
  • I created a test project in Eclipse with a copy in of the folders in my problem project for values, layouts, and drawables. The test app shows the actionbar. This leads me to think the problem doesn't lie with those folders.
  • I tried moving the style to the AndroidManifest to see if there was a conflict with another values folder or something, but still no actionbar.

The Code

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myApp"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="21"
    android:targetSdkVersion="21" />
<application
    android:icon="@drawable/launcher"
    android:label="@string/app_name" >
    <service android:name=".ServiceA" >
        <intent-filter>
            <action android:name="com.qualcomm.listen.sva.LOCAL_SERVICE" />
            <action android:name="com.qualcomm.listen.sva.REMOTE_SERVICE" />
        </intent-filter>
    </service>

    <activity
        android:name=".ux.dev.ActivityC"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name"
        android:theme="@style/ThemeA.Theme" >
    </activity>
    <activity
        android:name=".ux.dev.ActivityB"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name"
        android:theme="@style/ThemeA.Theme" >
    </activity>
    <activity
        android:name=".ux.dev.ActivityA"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:theme="@style/ThemeA.Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".ux.dev.ActivityD"
        android:configChanges="orientation|screenSize"
        android:label="@string/app_name"
        android:theme="@style/ThemeA.Theme" >
    </activity>
    <activity
        android:name=".ux.dev.ActivityE"
        android:label="@string/app_name"
        android:theme="@style/ThemeA.Theme" >
    </activity>
    <activity
        android:name=".ux.dev.ActivityF"
        android:label="@string/app_name"
        android:theme="@style/ThemeA.Theme" >
    </activity>

    <receiver android:name=".BootupReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
    <receiver android:name=".ScreenOnoffReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.SCREEN_OFF" />
            <action android:name="android.intent.action.SCREEN_ON" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
    <activity
        android:name=".ux.user.UserActivityA"
        android:label="@string/title_activity_edit_keyphrase"
        android:theme="@style/AppTheme" >
    </activity>
    <activity
        android:name=".ux.user.UserActivityB"
        android:label="@string/title_activity_select_action" >
    </activity>
    <activity
        android:name="ux.user.UserActivityC"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Material.Light" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

The problem is with ux.user.UserActivityC no having the actionbar.

like image 966
Patrick Avatar asked Dec 06 '25 02:12

Patrick


1 Answers

In your style.xml file (Which will be style.xml(v21))

<style name="AppTheme" parent="android:Theme.Material.Light">
</style>

Then make sure, you are extending your activity with

MainActivity extends ActionBarActivity

This will show actionBar even if you are using android:Theme.Material.Light

Moreover it is recommended that in material design, you should use Toolbar widget.

<android.support.v7.widget.Toolbar />

refer to this https://stackoverflow.com/a/30400594/3498931 , how you can create toolbar. It act as ActionBar in Material Design. Hope it helps!

like image 117
Ajay P. Prajapati Avatar answered Dec 08 '25 16:12

Ajay P. Prajapati