Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Theme.AppCompat.Light.DarkActionBar results in no ActionBar showing

I created a project with a blank activity (and then wrote code to put in a basic fragment - empty linear layout) in Android Studio but there is no ActionBar showing. Why?

Device: Emulator (Nexus 5 size), API 19

The main activity extends FragmentActivity.

The Android Studio generated styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

The activity layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/fragmentContainer"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />

The fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />

Manifest:

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".TestActivity"
            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>

</manifest>
like image 313
Don Rhummy Avatar asked Dec 20 '14 02:12

Don Rhummy


People also ask

How to set theme android?

Settings. Under Display Options, tap Theme. Select the theme for this device: Light—White background with dark text.

How do I set up no action bar?

If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.

What is AppCompat theme?

The AppCompat support library provides themes to build apps with the Material Design specification. A theme with a parent of Theme. AppCompat is also required for an Activity to extend AppCompatActivity . The first step is to customize your theme's color palette to automatically colorize your app.

How to create style xml android studio?

Create a file named styles. xml in the your application's res/values directory. Add a root <resources> node. For each style or theme, add a <style> element with a unique name and, optionally, a parent attribute.


1 Answers

Instead of extending FragmentActivity, I need the main class to extend AppCompatActivity.

As explained here:

http://developer.android.com/training/basics/fragments/creating.html

If you're using the v7 appcompat library, your activity should instead extend ActionBarActivity, which is a subclass of FragmentActivity (for more information, read Adding the Action Bar).

EDIT

ActionBarActivity is now deprecated. Use AppCompatActivity instead.

like image 147
Don Rhummy Avatar answered Oct 23 '22 11:10

Don Rhummy