Home » Android » Android Applications » How to Remove Title and Status Bar for Fullscreen Android Activity Using Java and Kotlin ?

How to Remove Title and Status Bar for Fullscreen Android Activity Using Java and Kotlin ?

In Android development, removing the title bar and status bar is often done to create a fullscreen immersive experience for the user. Here’s how you can hide the title and status bar using both Java and Kotlin.

1. Remove Title Bar

The title bar is typically the app’s name displayed at the top of the activity. To remove it:

  • In Java:
    You can hide the title bar by calling requestWindowFeature(Window.FEATURE_NO_TITLE) in your onCreate() method before setContentView().
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       setContentView(R.layout.activity_main);
   }
  • In Kotlin:
    Similarly, in Kotlin, you can hide the title bar as shown below:
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       requestWindowFeature(Window.FEATURE_NO_TITLE)
       setContentView(R.layout.activity_main)
   }

2. Remove Status Bar

The status bar displays system information like the clock and battery level. To hide it, use the following code in your onCreate() method:

  • In Java:
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
       setContentView(R.layout.activity_main);
   }
  • In Kotlin:
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                       WindowManager.LayoutParams.FLAG_FULLSCREEN)
       setContentView(R.layout.activity_main)
   }

3. Hiding Both Title and Status Bar

To completely remove both the title and status bar, combine the above steps:

  • In Java:
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
       setContentView(R.layout.activity_main);
   }
  • In Kotlin:
   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)
       requestWindowFeature(Window.FEATURE_NO_TITLE)
       window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                       WindowManager.LayoutParams.FLAG_FULLSCREEN)
       setContentView(R.layout.activity_main)
   }

4. Fullscreen Mode with System UI Visibility

For a more immersive experience where the system UI, such as navigation bars, is hidden, you can use View.SYSTEM_UI_FLAG_FULLSCREEN in Android API 30+:

  • In Java:
   View decorView = getWindow().getDecorView();
   decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
  • In Kotlin:
   val decorView = window.decorView
   decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN

This method hides the status bar, giving you a more immersive look.

Example: Hiding Title and Status Bar in Android Manifest

You can also hide the title bar directly in the AndroidManifest.xml by adding the following attributes to the activity tag:

<activity
    android:name=".MainActivity"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>

This will make your activity fullscreen without needing to modify your code.

By following these steps, you can easily remove the title bar and status bar in Android using Java and Kotlin to create a fullscreen, immersive user experience.


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment