Full Screen View

Full Screen View

⇒ 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.
  1. requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
  1. 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.
  1. this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //show the activity in full screen
 

Activity class File: MainActivity.java

package first.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); //will hide the title requestWindowFeature(Window.FEATURE_NO_TITLE); // hide the title bar getSupportActionBar().hide(); // enable full screen this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); } }
 

File: MainActivity.kt

package com.example.demoapi import android.os.Bundle import android.view.Window import android.view.WindowManager import androidx.appcompat.app.AppCompatActivity class ViewProduct : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) requestWindowFeature(Window.FEATURE_NO_TITLE) supportActionBar?.hide() this@ViewProduct.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) setContentView(R.layout.activity_view_product) } }