How to Enable Full-Screen Mode in Android?

 In this tutorial, we will learn how to activate full screen in Android Studio. For example, if we are viewing an image, we would prefer to do so in full screen mode. What we're going to do here is basically hide the navigation and status bar and enable full-screen mode of Mobile application.

There are many different method of full screen of application screen.

  •  Method 1

     Below code write in java class in your project

  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_FULLSCREEN);
  • Method 2 

     Below code write in Manifest.xml file on the project

 android:theme="@style/Theme.AppCompat.Light.NoActionBar"
  • Method 3 

     Below code write in styles.xml file on the project

 <item name="windowActionBar">false</item>
 <item name="windowNoTitle">true</item>


Step-by-Step Implementation

Step 1: Create a new project in Android  or you can use an already created project.  


Step 2: Create an activity_main.xml file in your layout folder. path (res>layout)
 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="80dp"
android:text="Candidroot solutions"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.842"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/txtMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginTop="296dp"
android:text="FullScreen Example"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtTitle" />

</androidx.constraintlayout.widget.ConstraintLayout>

Step 3: Create an MainActivity.java file in your package folder .

 Implement the same invoke the following code inside MainActivity.java file.

 import android.os.Bundle;
import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

}
}
Step 4: Output of above example


Happy coding!

365Bloggy June 12, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive