0

Im learning, stuck at simple problem of removing Android's action bar and seting app to full screen. Whole app should be in fullscreen, so I started with Manifest

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
    <activity
        android:name=".Main"
        android:screenOrientation="landscape"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

UI stays exactly the same = Stuck at default Look. Alright next I tried changing looks in Android studio GUI for activity_main.xml screen. That changes Design preview, but no effect in actual app. Still the same. Is this meant to change app or just design preview btw?

I tried changing in

<activity
        android:name=".Main"
        android:screenOrientation="landscape"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

:theme to @android:style/Theme.Holo.Light.NoActionBar.Fullscreen but now app crashes on startup.

I also tried making Custom theme in styles.xml, like this

<style name="CustomMyTheme" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

But same results. I don't understand why changing theme in manifest does not work. Is there some conflict in api version? Minimum is set to 15, 26 target and 22 emulator's version.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Jonzi
  • 141
  • 1
  • 2
  • 13

2 Answers2

0

Use the following theme to set application or any activity as fullscreen

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

You can also do it from Javacod. Add this code in your onCreate(); before super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
Sushin Pv
  • 1,826
  • 3
  • 22
  • 36
  • This was the first thing I tried and it doesn't change anything. (Look at first code snippet) – Jonzi Oct 27 '17 at 11:20
  • @Jonzi you are using `Theme.Holo.Light.NoActionBar.Fullscreen`. Try this one `Theme.NoTitleBar.Fullscreen` – Sushin Pv Oct 27 '17 at 11:21
  • @Jonzi The app crash because you are setting the wrong theme for your app – Sushin Pv Oct 27 '17 at 11:26
  • Hello, second Theme setting you suggested makes no difference. Still same default look. App only crashes when I apply such theme in Manifest to activity, but when aplied to it doesn't crash, but doesn't do anything also. Might be something wrong with my emulator? – Jonzi Oct 27 '17 at 11:34
  • @Jonzi apply this theme to your activity. it will work. If you just want to remove the action bar use this `android:theme="@style/Theme.AppCompat.Light.NoActionBar"` – Sushin Pv Oct 27 '17 at 11:39
  • Hello, this time it didn't crash for some reason, and it removed Label text but not ActionBar? This is result https://imgur.com/a/DoKIo Im confused D: Got meeting now, I will come back in few hours. Thanks for help anyway! – Jonzi Oct 27 '17 at 11:43
0

Try to use this code in your activity. Call the function before setContentView().

private void setFullScreen() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN
        );
    }
jknair0
  • 1,194
  • 13
  • 24
  • Why you are setting the FULLSCREEN flag for two times. And this is used to set the activity as fullscreen from Java code. This can be easily done from manifest only – Sushin Pv Oct 27 '17 at 11:25
  • Yeah I added just tried `getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);` It removes ActionBar alright, but I'd rather do it in manifest, just to learn what's wrong. Thanks anyway, I will set you to answer if noone else helps me with manifest – Jonzi Oct 27 '17 at 11:38