[Android application development] How to display in full screen (notification bar hidden)

Introduction

I want to display the Android application in full screen, but even if I select __ "Empty Activity" __ </ font> in the project initial settings (Activity), Since the notification bar is displayed, this time I would like to describe the settings around this notification bar collectively. (Written by [Mon] on May 15, 2017)

"Empty Activity" `` `selected at the time of initial project setup.

image.png (3.6 kB)

The result of Hello World using Empty Activity!

image.png (9.5 kB)

Hmmm, I want to hide __ "① Status bar" __ </ font> and __ "② Title bar" __ </ font>.

As a result of various investigations above, it seems that AndroidManifest.xml should be modified.

AndroidManifest.xml


(Change before) android:theme="@style/AppTheme"
(After change) android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

So, the status bar and title bar should disappear, but.

image.png (25.7 kB)

__ Error details __ </ font> java.lang.IllegalStateException: You need to use a Theme.AppCompat theme with this activity. Since it inherits AppCompat, please write according to it! I was angry, so I checked AppCompat and themes again.

How to set when MainActivity inherits AppCompatActivity

When I looked it up, it seemed that I could easily change it to full screen display, so Make a note of the procedure below.

  1. Modify style.xml
  2. Modify AndroidManifest.xml
  3. Run

About specific corrections


1. Modify style.xml

Project name> app > src > main > res > values > style.xml



 __(Before correction)__


#### **`style.xml`**
```xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

(Revised)

style.xml


<resources>
    <!-- Base application theme. -->
    <style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <!-- add Style -->
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
</resources>

#### 2. Modify AndroidManifest.xml (Change before)

AndroidManifest.xml


android:theme="@style/AppTheme"

↓ (After change)

AndroidManifest.xml


android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"

#### 3. Run (confirm full screen operation)

image.png (61.1 kB)

I was able to hide both the status bar and the title bar.

Thank you for reading to the end. If you like, please like it.

Recommended Posts