0

I want to remove the notification bar but the application keeps getting stopped. I tried the code below but it doesn't do anything.

    <activity
        android:name=".patient_pictureUpload"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Alec
  • 48
  • 1
  • 7
  • 2
    Does this answer your question? [Fullscreen Activity in Android?](https://stackoverflow.com/questions/2868047/fullscreen-activity-in-android) – Ananta Raha Jun 10 '21 at 05:57
  • If your crash is triggering by the ActionBarActivity [crashLog: “Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity”], then it seems the ActionBarActivity assuming that you are using an ActionBar, while with “Theme.NoTitleBar” themes remove the ActionBar (as that is part of the title bar on newer devices and ActionBarActivity assumes you are using a Theme.AppCompat theme which controls styling for the ActionBar). Change your activity to extend FragmentActivity with not having an Action Bar, if possible. – Akki Jun 10 '21 at 06:06
  • It's very difficult to debug a crash without a stack trace. See [Unfortunately MyApp has stopped. How can I solve this?](/q/23353173) for Android-specific advice, and [What is a stack trace, and how can I use it to debug my application errors?](/q/3988788) for advice on what to do once you have the stack trace. If you still need help, edit your question to include the **complete stack trace**, as well as **which line of your code** the stack trace points to. – Ryan M Jun 10 '21 at 06:50

1 Answers1

2

On Android 4.0 and Lower In AndroidManifest.xml -> inside the activity which you want to use, add the following to hide the status bar:

android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >

Programatically, by setting WindowManager flag:

Write a helper function

void hideStatusBar() {
        // For Android version lower than Jellybean, use this call to hide the status bar.
        if (Build.VERSION.SDK_INT < 16) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
           this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = getWindow().getDecorView();
            // Hide the status bar.
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

Use the helper function in onCreate()

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        hideStatusBar();
        // We should never show the action bar if the status bar is hidden, so hide that too 
//if necessary.
        getSupportActionBar().hide()  // if you have extended the activity from support lib like Appcompat, else use getActionBar().hide() here
           setContentView(R.layout.activity_main);
    }

Please Note:

  1. onCraete() will not get called always, so If you want system UI changes to persist as the user navigates in and out of your activity, set UI flags in onResume() or onWindowFocusChanged().
  2. Use it before super.onCreate(savedInstanceState); if it crash

Find more details from here

Akki
  • 775
  • 8
  • 19