LoginSignup
41
34

More than 5 years have passed since last update.

【 Android アプリ開発 】全画面表示を行う方法 ( 通知バー非表示 )

Last updated at Posted at 2017-05-15

はじめに

Androidアプリを全画面表示にしたいのだが、プロジェクト初期設定(Activity)で、「Empty Activity」を選択しても、
通知バーが表示されるので、今回はこの通知バーまわりの設定をまとめて記述したいと思います。
(2017/05/15[Mon] 執筆)

プロジェクト初期設定時に選択した、「Empty Activity」

image.png (3.6 kB)

Empty Activityを使用してHello Worldした結果!

image.png (9.5 kB)

うーん、「①ステータスバー」「②タイトルバー 」を非表示にしたい。

上記様々調べた結果、どうやらAndroidManifest.xmlを修正すれば良さそうです。

AndroidManifest.xml
(変更前) android:theme="@style/AppTheme"
(変更後) android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

で、ステータスバーもタイトルバーも消えてくれるはずだが、、。

image.png (25.7 kB)

エラー内容
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme with this activity.
AppCompatを継承してるからそれに沿った記述方法をしてくれ!と怒られたので、
再度AppCompatとテーマについて調べてみた。

MainActivityがAppCompatActivityを継承している場合の設定方法について

調べてみると、意外とあっさり全画面表示に変更できそうなので、
下記に手順を書き留めておく。

  1. style.xmlを修正
  2. AndroidManifest.xmlの修正
  3. 実行

具体的な修正箇所について


1. style.xmlを修正

プロジェクト名 > app > src > main > res > values > style.xml

(修正前)

style.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>

(修正後)

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. AndroidManifest.xmlの修正

(変更前)

AndroidManifest.xml
android:theme="@style/AppTheme"


(変更後)

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


3. 実行(フルスクリーンでの動作を確認)

image.png (61.1 kB)

ステータスバーもタイトルバーも非表示にすることができました。

最後までお読みいただき、ありがとうございます。
もしよろしければ「いいね!」お願いします。

41
34
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
41
34