By default every Android Activity will have a Navigation Bar or so-called "The Status Bar" (Update 2018: This is not true anymore - you can select a completely blank template with no Navigation Bar while creating a new project using Android Studio) this bar displays the title of the Activity, you might be working on a scenario where you want to have a full-screen display for your app, this can be done in two ways - by using the XML property or programmatically using Java/Kotlin code.
Method 1: Using AndroidManifest.xml
To hide the title bar and the navigation bar from an Android Activity to make your App utilize full screen, all we need to do is add the following attribute to the Activity tag(in AndroidManifest.xml) which needs no title bar.
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
Below is how the activity code will look like,
<activity
android:name="com.example.proj1.MainPage"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
If you want to make your whole application full screen then use the below code snippet in the App Manifest file.
<application
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
</application>
This is the most preferred way of setting your Activity full screen using Manifest XML file as it's easy to maintain.
This is an old post, as Android development has evolved maybe this may not hold true if you are on Android 4.0 or above (API 14), if you want to do the same thing using Java code this can be achieved as following,
Method 2: Using Java/Kotlin Code
Using the code you can archive this using the WindowManager flags. You may want to use this approach if you want to toggle between hiding and showing the status bar based on user interaction with the activity.
If the Android version is lower than Jellybean i.e. API 16 or lower,
//JAVA EXAMPLE
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
}
//KOTLIN EXAMPLE
class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT < 16) {
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
setContentView(R.layout.activity_main)
}
}
If the Android version is 4.1 or higher,
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
getActionBar().hide();
If you just want to hide the title bar, you can use: this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Comments:
Facing issues? Have Questions? Post them here! I am happy to answer!
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Android Emulator cannot be opened because the developer cannot be verified. [M1 Mac]
- How to Change Android Toast Position?
- Fail to connect to camera service Android java RuntimeException
- How to create Custom RatingBar Android Programming Tutorial
- Fixing Android unknown error 961 while downloading app
- Android AlertDialog with Yes No and Cancel Button
- Share or Send SMS via Android Intent
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Pass data between two Android Activities and access it using Intent
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android EditText Cursor Colour appears to be white
- Android Development - How to switch between two Activities
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Android : Remove ListView Separator/divider programmatically or using xml property
- Android is starting optimizing... app 1 of 1
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- AlertDialog with single button example : Android
- Android : Exception raised during rendering: action_bar API 22
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Center align text in TextView Android Programming
- How to Download and Install Android adb Tool on Linux, Mac or Windows
- Multiline EditText in Android Example
- SharePoint Open in the client application document opens in browser - Java
- Fix: Windows 11 Something went wrong - We coudnt find info for that Account (Windows 365 Business) - Windows-11
- How to Change Notepad++ Toolbar Icons and size - NotepadPlusPlus
- How to know the Python Version of Jupyter Notebook - Python
- Save cURL Command Output to a external file - cURL
- Android: Save Data in local Db using Android Room - Android
- Solution: AWS S3 CLI Command AccessDenied - S3
- Microsoft Excel Fuzzy Lookup Add-in - Microsoft
> admin: Thanks, I have updated the text of this post with this note!