Home » Android » Android Applications » How to remove/hide Title/Status bar from the android to make activity fullscreen using JAVA and Kotlin ?

How to remove/hide Title/Status bar from the android to make activity fullscreen using JAVA and Kotlin ?

If you want to hide the top title bar ( which is also called as Status bar ) which display battery status, network status, alerts etc while user is browsing your application. This can be done in two ways,

Hide by setting an activity theme in your app’s manifest file. Setting an activity theme in your app’s manifest file is the preferred approach if the status bar should always remain hidden in your app.

Modify your application AndroidManifest.xml as below,

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

The advantages of using an activity theme are as follows:

  • It’s easier to maintain and less error-prone than setting a flag programmatically.
  • It results in smoother UI transitions, because the system has the information it needs to render your UI before instantiating your app’s main activity.

Programmatically Hide Title bar in Kotlin

import android.view.Window
import android.view.WindowManager

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

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

        setContentView(R.layout.activity_layout_main)
}

}

As we can see in above code you will have to add following two lines and its associated imports in activities onCreate function,

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

here, “this” refers to activity.

Programmatically Hide Title Bar in Java

For hiding title bar in JAVA, you have to add same code in onCreate of Activity in your android java code.


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

Leave a Comment