Patrick
Patrick

Reputation: 14278

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

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.

Upvotes: 3

Views: 2006

Answers (1)

Ajay P. Prajapati
Ajay P. Prajapati

Reputation: 2023

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!

Upvotes: 2

Related Questions