Android Hide Title Bar

We are going to discuss the ways to hide the title bar and to display the content in full-screen mode.
requestWindowFeature(Window.FEATURE_NO_TITLE): It is a method of Activity, which must be coded before the setContentView method. It is called to hide the title.

Code that hides title bar of activity:

  • getSupportActionBar() method: Used to retrieve the instance of the ActionBar class.
  • hide() method of the ActionBar class: Used to hide the title bar.
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title 
getSupportActionBar().hide(); //hide the title bar

Code that enables the full-screen mode of activity:

  • setFlags() method of Window class: Used to display content in the full-screen mode.
  • WindowManager.LayoutParams.FLAG_FULLSCREEN constant: It is passed in the setFlags method.
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
WindowManager.LayoutParams.FLAG_FULLSCREEN); //show the activity in full screen  

Android Hide Title Bar and Full Screen Example:

Code to hide the title bar in android.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">
 
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Hello World!"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent" />
 
</android.support.constraint.ConstraintLayout>

Activity class:

File: MainActivity.java

package com.example.app1;
 
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
 
public class MainActivity extends AppCompatActivity {
 
   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
       getSupportActionBar().hide(); // hide the title bar
       this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
               WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
       setContentView(R.layout.activity_main);
 
 
   }
}

Output:

Content Protection by DMCA.com
Please Share