"CSS Foundations" was retired on July 8, 2016. You are now viewing the recommended replacement.

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 an Interactive Story App (Retired) User Input Hiding the ActionBar with an App Theme

kelvin gwaruka
kelvin gwaruka
931 Points

Action bar not removing from the emulator

The action bar is still present on my app when i run on the emulator. I am running android Studio version 2.2.3. My target API level is set to 24.

My styles.xml is as shown below

<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>

And my v21/style.xml file is

<resources>

<style name="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

</resources>

I notice that Ben's target API in the video is set to 21. I have changed my target API from 24 to 21 via gradle.module and syncronised but still the action bar appears on my emulator device. Has anyone been able to get around this

3 Answers

Hi Kelvin,

does your problem still exist? I just wondered if the action bar vanishes in your activity's preview in android studio or not. If yes I'd recommend doing a clean build by picking "Build -> Clean Project" from the menu and compiling again.

I recommend finding out why the change in your styles.xml is ignored. But there is another (quick and dirty) way to hide the Action Bar by adding this to your onCreate-method:

getSupportActionBar().hide();
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide();
    setContentView(R.layout.activity_main);
}
anna lobers
anna lobers
707 Points

Benjamin i tried that but then i got a null pointer excption: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.hide()' on a null object reference

jessica killeen
jessica killeen
4,549 Points

Hi there I am experiencing the same issue, and likely because I have a different version of Android Studio from previous lesson.

This is how my styles.xml was built when I created project: <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="Theme.AppCompat.Light.NoActionBar"/>
<style name="AppTheme.PopupOverlay" parent="Theme.AppCompat.Light.NoActionBar"/>

</resources>

On the video, when the styles.xml file is opened, there is much less code, i.e.:

<resources>
<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> </resources>

I think my issue has to do with the extra style names at the bottom. If I remove them I get an error message. If I remove them and other references to them, I also get an error message.

Any suggestions? Thanks! Jessica

kelvin gwaruka
kelvin gwaruka
931 Points

Thanks Benjamin, but unfortunately adding 

getSupportActionBar().hide();

gives me a null pointer exception too and app crashes. I will update you Anna with any solution i have on this issue. If you figure is first please share.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I've tried everything I know to get rid of the action bar. I thought I'd downloaded the same version as the video but I'm on AP23. The app functionally works as the video but for me, there's too many visual differences and quirks to the video so I'm just going to move on I think.

So long as we all understand there are going to be little differences and get to know the software we should be fine. :-)

kelvin gwaruka
kelvin gwaruka
931 Points

I agree with you Jonathan. I have exhausted all the options i can think of. Been on stack overflow and github but doesn't seem to help.