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.

Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question