Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (2014) Creating the Screen Layout Using a Fullscreen Theme

My action bar does not go

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

//Java code

import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem;

public class FunFacts extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fun_facts);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

......

10 Answers

John Caraballo
John Caraballo
19,943 Points

Remove this from activity_fun_facts.xml and the action bar will go away:

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>
Matthew McGuff
Matthew McGuff
4,355 Points

There is a little more than just removing the code above. You also need to remove the following from line 18 and 19 from FunFactsActivity.java :

          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

This code creates an object that references the wrapper that was deleted above. If not removed you will get the following Gradle build error:

Error:(18, 54) error: cannot find symbol variable toolbar

Hi again, I didn't realize what was going on. I found out that a recent update put in the ToolBar and the floating SnackBar thingie. You can probably delete this from FunFactsActivity.java too.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });```

If you are doing Fun Facts, you shouldn't have any more than the code below. I don't know where the rest might have come from, unless you somehow added an app theme, or 3.. In the code I pasted, you don't even really need the code after 'customize your theme here', except for the closing style tag.

           <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
            ```
And in the java code, this part, right after the onCreate method is MAKING a ToolBar., although it seems like it might be making a floating one... so, for Fun Facts, unless you are revising it to make it your own way, you don't need any of this at all.
  ```java
             Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
            ```

I have tried to format that answer properly three times, and something isn't working about it;.

you don't need this compile 'com.android.support:design:23.0.1' in your build.gradle file

+compileSdkVersion 23 buildToolsVersion "23.0.1"

  • minSdkVersion 14
  • targetSdkVersion 23

are all fine.

Thanks Susan and John.

Both code segments must be moved or commented out by the way. Now it is working...no toolbar

Vilmar Simson
Vilmar Simson
963 Points

Susan and John, thank you both for helping. Sorted it on 1.4 for me.

I have both API 23 and API 19 installed..is that a problem?

my build.gradle module:app

apply plugin: 'com.android.application'

android { compileSdkVersion 23 buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "teamtreehouse.funfactsv2"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:design:23.0.1' }

You can have as many copies of Android Studio on your computer as you want (or can fit.) So, if you wanted to have Eclipse, plus an old version of Studio, and the latest version of Studio on your computer, you could do that.

But, then you download the SDK with the SDK manager. I think that's what you're talking about. You check boxes in the SDK manager and download. In that, you could check ALL the boxes if you want to, and have the time and the space on your computer. I have the basics of at least 15 to the latest on mine.

I think maybe what you could have done is move something, like a toolbar into your visual layout screen.

but if you delete everything BELOW setContentView(R.layout.activity_fun_facts); in the example you posted, it should go away.

I am pretty sure you don't need anything EXCEPT< style name="AppTheme" parent= "Theme.AppCompat.Light.NoActionBar" >< /style> in your xml. I think you can delete the rest of what you had there.

I did delete now and my code now is

public class FunFacts extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fun_facts);
    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);


}

}

but the problem now is

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" //here is error..its red highlighted tools:showIn="@layout/activity_fun_facts" tools:context=".FunFacts">

<TextView android:text="Hello World!" android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>