Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

pdiaz
pdiaz
16,073 Points

Can someone help with android theme?

Hey guys, I'm having a problem with my app, in which I can only use the default app theme in order for my app to work. If I put a another theme in, the app will crash. I only want my app to have the theme.black.NoTitleBar.fullscreen. Is there any way for me to apply this theme without having my app crashing.

2 Answers

It's a bug in the ADT as I suppose

The error relates to java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

The video in treehouse uses the Theme called ** Theme.Black.NoTitleBar.Fullscreen ** . Are you using this?

If yes, then the new android update no longer supports this. However there is a work around as proposed by treehouse


1) Change your project back to using "AppTheme" like it was before in AndroidManifest.xml and the preview.

2) Add the following two lines to the file res/values/styles.xml (inside the <style name="AppTheme"> tag):

<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

3) Set the background color to black in the file res/layout/activity_main.xml. The root element, RelativeLayout, is the one that makes up the whole screen. Add this line after the layout_height line but before the closing angle bracket >:

android:background="@android:color/black"

4) Change MainActivity to extend Activity, not ActionBarActivity


Hope this helps. Ask again if you have doubts.

pdiaz
pdiaz
16,073 Points

how am I suppose to extend activity?

Extend is a keyword in Java that implies inheritance.

By convention it means remove ActionBar from ActionBarActivity so that it reads Activity in your MainActivity.java file

Hope I made sense. Ask again if you have a doubt

pdiaz
pdiaz
16,073 Points

ok so I changed it to this: public class MainActivity extends Activity{ but I'm receiving a bunch of errors so what should I do now?

That's correct. After you do that you will need to take care of your import using ctrl + shift + o (Windows) and cmd + shift + o (Mac)

If that still doesn't work feel free to take a screen shot or paste errors here so that we can have a look

pdiaz
pdiaz
16,073 Points

Thanks so much for your help, though how do you take screenshots on a windows computer.

alt + print srcn button. Next open MS Paint and paste the screenshot in it and edit.