This example explains how to set Application to fullscreen in android.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it FullScreenDemo.
2.) Write following into main.xml:
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <view class="com.example.FullScreenDemo.FullScreenDemo$IV" android:id="@+id/image" android:src="@drawable/skycubemap2" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="center" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginBottom="25dp" android:layout_gravity="bottom|center" android:background="#60000000" android:padding="8dp" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" > <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFFFF" android:textSize="16dp" android:textStyle="bold" android:gravity="left" /> <TextView android:id="@+id/text2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFFFF" android:textSize="11dp" android:textStyle="bold" android:gravity="left" /> </LinearLayout> <TextView android:id="@+id/switchy" android:background="#C0000000" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginTop="4dp" android:padding="10dp" android:textColor="#FFFFFFFF" android:textSize="11dp" android:textStyle="bold" android:clickable="true" android:onClick="clicked" android:text="Switch" /> </LinearLayout> </FrameLayout>
3.) Select a wallpaper or background image and put it into drawable folder. Either rename the image “skycubemap2” or change the name into main.xml accordingly.
4.) Run for output.
Steps:
1.) Create a project named FullScreenDemo and set the information as stated in the image.
Build Target: Android 4.0
Application Name: FullScreenDemo
Package Name: com. example. FullScreenDemo
Activity Name: FullScreenDemo
Min SDK Version: 14
2.) Open FullScreenDemo.java file and write following code there:
package com.example.FullScreenDemo; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.AttributeSet; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; public class FullScreenDemo extends Activity { public static class IV extends ImageView { private FullScreenDemo mActivity; public IV(Context context) { super(context); } public IV(Context context, AttributeSet attrs) { super(context, attrs); } public void setActivity(FullScreenDemo act) { mActivity = act; } public void onSystemUiVisibilityChanged(int visibility) { mActivity.getState().onSystemUiVisibilityChanged(visibility); } } private interface State { void apply(); State next(); void onSystemUiVisibilityChanged(int visibility); } private class NormalState implements State { public void apply() { display("Normal"); setFullscreen(false); mImage.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); } public State next() { return new FullscreenState(); } public void onSystemUiVisibilityChanged(int visibility) { } } private class FullscreenState implements State { public void apply() { display("FULLSCREEN"); setFullscreen(true); } public State next() { return new NormalState(); } public void onSystemUiVisibilityChanged(int visibility) { } } private void setFullscreen(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); } private void display(String text) { mText1.setText(text); } State getState() { return mState; } static int TOAST_LENGTH = 500; IV mImage; TextView mText1, mText2; State mState; public FullScreenDemo() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); winParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; win.setAttributes(winParams); setContentView(R.layout.main); mImage = (IV) findViewById(R.id.image); mImage.setActivity(this); mText1 = (TextView) findViewById(R.id.text1); mText2 = (TextView) findViewById(R.id.text2); } @Override public void onAttachedToWindow() { mState = new NormalState(); mState.apply(); } @Override protected void onResume() { super.onResume(); } public void clicked(View v) { mState = mState.next(); mState.apply(); } }
3.) Compile and build the project.
Output