Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Hide Title Bar


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.

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

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.

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

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
  1. <RelativeLayout xmlns:androclass=“http://schemas.android.com/apk/res/android”
  2.     xmlns:tools=“http://schemas.android.com/tools”
  3.     android:layout_width=“match_parent”
  4.     android:layout_height=“match_parent”
  5.     android:paddingBottom=“@dimen/activity_vertical_margin”
  6.     android:paddingLeft=“@dimen/activity_horizontal_margin”
  7.     android:paddingRight=“@dimen/activity_horizontal_margin”
  8.     android:paddingTop=“@dimen/activity_vertical_margin”
  9.     tools:context=“.MainActivity” >
  10.     <TextView
  11.         android:layout_width=“wrap_content”
  12.         android:layout_height=“wrap_content”
  13.         android:text=“@string/hello_world” />
  14. </RelativeLayout>

Activity class

File: MainActivity.java
  1. package com.Kreationnext.hidetitle;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.view.Menu;
  5. import android.view.Window;
  6. import android.view.WindowManager;
  7. public class MainActivity extends Activity {
  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  12.       /*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  13.                   WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask
  14.       */
  15.         setContentView(R.layout.activity_main);
  16.     }
  17. }

Output: Hiding the Title Only

hidetitle1

Output: Hiding the TitleBar and enabling FullScreen

hidetitle2

Comments

comments