-1

I have a fragment that shows a camera preview and a button, and in the activity for the fragment I'm trying to hide the title bar, but it doesn't work. The title bar still shows. In the activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    // Hide the window title
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Hide the status bar and other OS-level chrome
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    super.onCreate(savedInstanceState);
}

I'm following the book Android Programming: The Big Nerd Ranch Guide.

user3424455
  • 105
  • 1
  • 8
  • possible duplicate of [How to hide app title in android?](http://stackoverflow.com/questions/2862528/how-to-hide-app-title-in-android) – Leandros May 29 '15 at 08:16
  • Not exactly a duplicate of that said question, but rather: http://stackoverflow.com/questions/4250149/requestfeature-must-be-called-before-adding-content – Leandros May 29 '15 at 08:21

2 Answers2

0
@Override
protected void onCreate(final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // Make this activity, full screen
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // Hide the Title bar of this activity screen
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);

...

}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • The book says "The calls to requestWindowFeature(…) and addFlags(…) must be made before the activity’s view is created in Activity.setContentView(…), which, in CrimeCameraActivity, is called in the superclass’s implementation of onCreate( Bundle)." – user3424455 May 28 '15 at 19:39
  • In facts, as you can see, I do it **before** `setContentView()` (and **after** `super.onCreate()` )... – Phantômaxx May 28 '15 at 19:46
  • I'm sorry I forgot to add the setContentView(). However it still seems to crash with "android.util.AndroidRuntimeException: requestFeature() must be called before adding content". – user3424455 May 28 '15 at 20:04
  • Yes: **before** `setContentView()`!! – Phantômaxx May 28 '15 at 20:34
0

In manifest change this

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Mayank
  • 1,364
  • 1
  • 15
  • 29
  • It doesn't let me use that. "java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity". Also would that make the entire app not have a title bar? I only want to hide it in the one activity. – user3424455 May 28 '15 at 19:18
  • No, you can set a theme for a single activity as well. Although you can make your own theme if the standard themes are not what you expect. See [this](http://stackoverflow.com/questions/3758942/how-to-create-a-custom-theme-and-use-it-in-android-application) – Mayank May 29 '15 at 19:02