fastread homefastrread library fastread menu

Android : Hide Title Bar Example

Tutorial by:      Date: 2018-01-16 09:36:30

❰ Previous Next ❱

Now, we will 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.


    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
     requestWindowFeature(Window.FEATURE_NO_TITLE);//will hide the title not the title bar  
        setContentView(R.layout.activity_main);  
    }  
}  

The setFlags() method of Window class is used to display content in full screen mode. You have to need to pass the WindowManager.LayoutParams.FLAG_FULLSCREEN constant in the setFlags method.


@Override  
protected void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    requestWindowFeature(Window.FEATURE_NO_TITLE);  
    //code that displays the content in full screen mode  
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask  
    setContentView(R.layout.activity_main);  
}  

Android Hide Title Bar Example

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

activity_main.xml

File: activity_main.xml

<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:paddingBottom="@dimen/activity_vertical_margin"  
    android:paddingLeft="@dimen/activity_horizontal_margin"  
    android:paddingRight="@dimen/activity_horizontal_margin"  
    android:paddingTop="@dimen/activity_vertical_margin"  
    tools:context=".MainActivity" >  
    <TextView  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="@string/hello_world" />  
RelativeLayout>  

Activity class

File: MainActivity.java

package com.fastread.hidetitle;  
import android.os.Bundle;  
import android.app.Activity;  
import android.view.Menu;  
import android.view.Window;  
import android.view.WindowManager; 
public class MainActivity extends Activity {  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
      /*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask 
      */  
        setContentView(R.layout.activity_main);  
    }  
} 

❰ Previous Next ❱