0 votes
in Android by
Android Hide Title Bar and Full Screen Example

1 Answer

0 votes
by
edited by
In this example, we are going to explain how to hide the title bar and how to display content in full screen mode.

The requestWindowFeature(Window.FEATURE_NO_TITLE) method of Activity must be called to hide the title. But, it must be coded before the setContentView method.

Code that hides title bar of activity

The getSupportActionBar() method is used to retrieve the instance of ActionBar class. Calling the hide() method of ActionBar class hides the title bar.

requestWindowFeature(Window.FEATURE_NO_TITLE);//will hide the title   

getSupportActionBar().hide(); //hide the title bar  

Code that enables full screen mode of activity

The setFlags() method of Window class is used to display content in full screen mode. You need to pass the WindowManager.LayoutParams.FLAG_FULLSCREEN constant 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

Let's see the full code to hide the title bar in android.

activity_main.xml

File: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>  

<android.support.constraint.ConstraintLayout xmlns:android=""

    xmlns:app=""

    xmlns:tools=""

    android:layout_width="match_parent"  

    android:layout_height="match_parent"  

    tools:context="first.javatpoint.com.hidetitlebar.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 first.javatpoint.com.hidetitlebar;  

  

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);  

  

  

    }  

}

Related questions

0 votes
asked Aug 29, 2023 in Android Library by rahuljain1
0 votes
asked Sep 1, 2023 in Android by rajeshsharma
...