0

Before someone marks this as a duplicate, I've spent hours looking through google and StackOverflow for answers to my problem and have not found any.

I've used the Android Studio Login Activity but I can't get the title bar to go away in that one activity (not the whole app). I've read over at least 10 different articles on how to do this, most of them say the same thing and none of it works. In fact, editing my .java class crashes my app. Is there a relation to this and the pre-built code involved in the Login Activity?

I've tried the following blocks of code in different orders in one of my java files:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

I've tried setting the NoActionBar theme in my XML file, as well as adding to the Manifest (which I don't want to do because that blankets the app... I just want the one page (login)'s title bar to go away.

I've tried everything that I could find on here and on google's search. Has anyone else ran into this problem while using the Login Activity in Studio?

Also, I found this answer -

"You should use 'NoActionBar' Style in 'styles.xml'. Than create toolbar in your layout and add child view to your toolbar, set title and modify as you like. "

    • This also does not work. I found that answer here: StackOverflow

Still no luck. I'd appreciate any advice. Thanks for your time!

EDIT: Someone told me to delete the ActionBar Class:

private void setupActionBar() { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); setupActionBar(); } }

Also deleted the call to actionBar. -- This also did not work.

I found this topic on Stack: Android Theme.TitleBar does not work This was not helpful at all.

I tried this topic too which was also useless: How to hide the title bar for an Activity in XML with existing custom theme

3 Answers3

0

When we create an Activity using Login Template, we see something like this -

public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> {....

Now, we can see that our Activity extends AppCompatActivity. Thus, we need to create a custom style that extends AppCompat Theme, and override it to hide status bar.

First, in styles.xml, create a custom style as follows -

<style name="MyNoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Now, in AndroidManifest.xml, declare the "theme" attribute for the LoginActivity as follows -

 <activity
            android:name=".LoginActivity"
            android:theme="@style/MyNoActionBarTheme"
            android:label="@string/title_activity_login">
</activity>

As you can see from the image, the status bar is gone and the activity is now full-screen.

Do tell if this does not work for you. I too created a Login Template in Android Studio as the very first step.

Kunal Chawla
  • 1,236
  • 2
  • 11
  • 24
  • Sorry. Yes the style name should be the same. My mistake. Edited the answer now. – Kunal Chawla May 30 '17 at 18:55
  • I'd hug you if I could. You're a lifesaver. And a huge time saver! My god... So much time on Stackoverflow looking through tons of questions similar to mine and no luck. You jump on and boom! It's working. Thank you! – InstaSteve May 30 '17 at 18:57
  • @InstaSteve haha. No problem man. Kindly mark the answer as Accepted so that its helpful to others as well in the future. Thanks ! – Kunal Chawla May 30 '17 at 18:58
  • Done! I hope other people will find this. I was worried I'd go bald pulling my hair out.. Take care and all the best to you! – InstaSteve May 30 '17 at 19:01
  • @InstaSteve Thanks a ton and same to you ! Don't worry, it happens to all of us, which is why we are here to help each other. Happy coding ! – Kunal Chawla May 30 '17 at 19:02
0

If your LoginActivity is derived from AppCompatActivity then use below code to hide action bar.

getSupportActionBar().hide();

And if you are using toolbar as action bar then use this

((AppCompatActivity)getActivity()).getSupportActionBar().hide();
Fahadsk
  • 1,099
  • 10
  • 24
  • getSupportActionBar().hide(); did not work for me. Sorry, I should have mentioned in my question that I tried this already. Wasn't using a toolbar. Thanks though! – InstaSteve May 30 '17 at 18:59
0

For AppCompat, following solution worked for me:

Add new theme style with no action bar in your styles.xml and set parent="Theme.AppCompat.NoActionBar".

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>

</style>


Now implement the same theme style to your splash screen activity in androidManifest.xml

<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // apply splash them here 

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

Here is result:

enter image description here

Krunal
  • 77,632
  • 48
  • 245
  • 261