Michael van der Horst
Michael van der Horst

Reputation: 550

How can you check if status bar is visible in Android

What i want to reach is, that the user can't go out of the activity except when he presses one of the supplied buttons.
I've already caught the home and back button, but when i try to remove the status bar, my problems begin. I would like to have one of the following:

  • Status bar always invisible in Activity2
  • Status bar inaccessible, it is visible, but you can't activate it (see incoming call screen as example)
  • If I go for solution 1, this isn't possible if my application is running and Activity1 is showing the status bar, then Activity2 is shown under the status bar, the status bar overlays the top of Activity2
    Except when I start Activity2 from another application, then Activity2 isn't showing the status bar. Status bar overlays Activity2 No Status Bar visible here What am I doing wrong?

    Part of AndroidManifest.xml:

            <activity
            android:label="@string/app_name"
            android:launchMode="standard"
            android:name=".Activity1"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:launchMode="standard"
            android:name=".Activity2"
            android:noHistory="true"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter >
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.MONKEY" />
            </intent-filter>
        </activity>
    

    Upvotes: 3

    Views: 5518

    Answers (3)

    Vadim Osmanov
    Vadim Osmanov

    Reputation: 71

    To check status bar visibility try this code:

    public boolean isStatusBarVisible() {
        Rect rectangle = new Rect();
        Window window = getActivity().getWindow();
        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
        int statusBarHeight = rectangle.top;
        return statusBarHeight != 0;
    }
    

    Upvotes: 4

    Michael van der Horst
    Michael van der Horst

    Reputation: 550

    I had to start my activity in android:launchMode="singleInstance" and in OnAttachedToWindow() i had to call this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); Now the status bar won't be shown even if other Activities in the same application do show the status bar.

    Upvotes: 1

    yonilx
    yonilx

    Reputation: 165

    I think this guide can be helpful for theming

    http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/

    Upvotes: 2

    Related Questions