2

This is in the design interface.

enter image description here

This is the emulator.

enter image description here The blue bar comes out of nowhere. I tried something like NoTitleBar, and the app just crashes. Someone help me Please!

Update my question. The extending to Activity does not work.

Alan Zhu
  • 21
  • 4
  • Possible duplicate of [Remove Default Title Bar](http://stackoverflow.com/questions/9561178/remove-default-title-bar) – Ruchir Baronia Dec 23 '15 at 04:22
  • 1
    @RuchirBaronia: no it is not a duplicate. The one you linked to is for titlebar. This question is for actionbar/toolbar – Viral Patel Dec 23 '15 at 05:21

7 Answers7

4

Extend just Activity instead of AppCompatActivity in your Java class and the toolbar would be gone.

And remove the code referencing toolbar from onCreate() (if any was generated) and anywhere else (if you manually added) after changing the extended class, else you may see errors.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
  • Hi, thanks for your answer. I've tried that but it doesn't work. See my update in the question. – Alan Zhu Dec 25 '15 at 00:45
  • It has to. If you are not extending AppCompatActivity, you'll have no toolbar automatically. If you still see it search for the word "toolbar" in your Java file and see of you have manually added the toolbar. Remove those limes of code and you should be good to go. – Viral Patel Dec 29 '15 at 05:29
2

change your theme in styles.xml to Theme.AppCompat.Light.NoActionBar no extra code needed!

Kosh
  • 6,140
  • 3
  • 36
  • 67
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/10659285) – Shahzad Barkati Dec 23 '15 at 04:56
  • @SHAZ It does. When he referred to blue bar he meant the toolbar "actionbar" and by default android has a darkActionBar when you choose one of the templates Android studio provides. Please before bashing on people get your facts together. – Kosh Dec 23 '15 at 05:00
  • Hi, thank you very much for your help. I've tried your method but the outcome is it changes the blue bar to a white one...Well, if the background is white, it may look like it doesn't have the bar, but my background is grey. I wish I could post another picture but I can't because of the reputation stuff. – Alan Zhu Dec 25 '15 at 00:49
1

Firstly open the activity_main.xml then there will be somecode like this one

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

delete the above code from activity_main.xml

Now open the MainActivity.java and delete the below code

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

after this your problem should be solved.

  • Thanks, this actually works! Thank you so much! I've tried many methods but I just ignored that this setting in the activity main. – Alan Zhu Dec 30 '15 at 09:48
  • dude you can just hit +1 button so that other can benefit from it.. because i also faced this problem and it took me 3 days to figure this out because when i googled it i found nothing about it so i myself have to figure it out. – Manish Verma Dec 31 '15 at 07:10
  • Hey, of course I want to click like! But my reputation is like 6, only people with reputation over 15 can click like! Sorry for that, you did an amazing job! If I got more "reputation", I will come back and like! So, for now, what I can do is screaming out :" Somebody come here and Click like! This is the only useful answer for the problem!!!" – Alan Zhu Jan 03 '16 at 02:46
0
 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:windowNoTitle">true</item>
</style>

make sure you are not using getActionbar() or getSupportedActionbar in any activity that using this theme otherwise you will get NullPointerException

Rajesh
  • 2,618
  • 19
  • 25
0

If any of the above doesn't work then, create a new style in your Style.xml file

 <style name="AppTheme.NoActionBar" >
     <item name="windowActionBar">false</item>
     <item name="windowNoTitle">true</item>
 </style>

And in AndroidManifest.xml file, set your activity theme to the one you create :

<activity
        android:name=".Example"
        android:label="Example"
        android:theme="@style/AppTheme.NoActionBar"/>
Sachin Parashar
  • 1,067
  • 2
  • 18
  • 28
  • Hi, thanks for your answer. This was originally in my code, but I still have the bar. – Alan Zhu Dec 25 '15 at 00:55
  • there must be two xml files.. one will be content_example.xml and other will be activity_example.xml. Can you post code of both of those files? – Sachin Parashar Dec 26 '15 at 05:42
0

Well i had the same issue some time ago, and hiding it dynamically through code was the only solution that worked. In the onCreate() method do the following:-

getSupportActionBar().hide();

This will definitely work.

-1

use theme with actionbar like Theme.AppCompat.Light.DarkActionBar and in your activity use getSupportActionbar().hide(); in onCreate before setContentView()

Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177