Alex.Zaiats
Alex.Zaiats

Reputation: 138

notification bar in libgdx game

I want to create game using Libgdx engine. It's create by default FULLSCREEN game without notification bar.
Can i create game with notification bar?

Upvotes: 6

Views: 2614

Answers (3)

Luke
Luke

Reputation: 153

I run into a confusion here and couldn't make it work for a while on Android Lollipop. I had to actually merge all the code provided here in the answers, to make my app show status bar.

So the final working code for me looks like this:

Java part - combining relative layout and hideStatusBar config (thanks to LiamJPeters)

protected void onCreate (Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

    config.hideStatusBar = false;

    RelativeLayout layout = new RelativeLayout(this);
    layout.addView(initializeForView(new MyAndroidApp(), config));
    setContentView(layout);
}

And styles.xml part - windowFullscreen to false (thanks to Bernrd K.)

<resources>
    <style name="GdxTheme" parent="android:Theme">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowFullscreen">false</item>
    </style>
</resources>

Note: windowNoTitle has nothing to do with status bar itself. Depends what you need, but the xml above shows the status bar only, no titles.

Upvotes: 1

Bernd K.
Bernd K.

Reputation: 91

Since I am not (yet) allowed to comment I will make it an answer. Basically everything said by LiamJPeters helps, except you have set up the project recently from scratch with one of the newer libgdx nightlies, then there will also be a "res/values/styles.xml" which is referenced in the manifest.

I had to change two settings there (in addition to everything written by LiamJPeters) to make it finally show the notification bar and the window title:

<resources>
    <style name="GdxTheme" parent="android:Theme">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
        <item name="android:windowNoTitle">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowFullscreen">false</item>
    </style>
</resources>

Upvotes: 7

LiamJPeters
LiamJPeters

Reputation: 486

In the Android starter:

public class MainActivity extends AndroidApplication {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.hideStatusBar = false;
        initialize(new MainClass(), cfg);
    }
}

The important line here being cfg.hideStatusBar = false;

Hope that helps

EDIT

Ok so I've done a bit of research on the subject and it turns out it's pretty easy. I looked on the libgdx wiki page for adding admob ads. Follow all the steps except adding the ads!

Below is modified code for setting up a non-fullscreen android app:

public class MainActivity extends AndroidApplication {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        RelativeLayout layout = new RelativeLayout(this);
        layout.addView(initializeForView(new MainClass(), false));
        setContentView(layout);
    }
}

You can add all the layout parameters you want very easily by googleing "RelativeLayout layoutParams". Hope this helps. Please mark the question as answered.

Upvotes: 6

Related Questions