Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Figure out whether status bar is at top or bottom?

Tags:

android

I am trying to figure out how I can tell the location of the status bar (top or bottom). I tried to inspect HierarchyViewer but didn't see the status bar view.

Really what I need to figure out is, given a context, a way to return a boolean (true if bar is on top, false if it isn't -- like it isn't on most tablets). I wrote a simple solution to try and figure out of the status bar is at the top or bottom, but it doesn't seem to be helping:

private boolean isStatusBarAtTop(){
    if (!(getContext() instanceof Activity)) {
        return !getContext().getResources().getBoolean(R.bool.isTablet);
    }

    Window window =  ((Activity) getContext()).getWindow();

    if(window == null) {
        return !getContext().getResources().getBoolean(R.bool.isTablet);
    }

    Activity activity = (Activity)getContext();
    Rect rect = new Rect();

    window.getDecorView().getWindowVisibleDisplayFrame(rect);
    View ourView = window.findViewById(Window.ID_ANDROID_CONTENT);

    Log.d("Menu","Window Top: "+ ourView.getTop() + ", "+ourView.getBottom()+ ", "+ourView.getLeft()+", "+ourView.getRight());
    Log.d("Menu","Decor View Dimensions"+rect.flattenToString());

    return  ourView.getTop() != 0;
}

And for some reason I get the following as output (running on Nexus 7 Tablet):

D/Menu(1007): Window Top: 0, 0, 0, 0
D/Menu(1007): Decor View Dimensions0 0 800 1216

What am I thinking/doing wrong?

like image 318
hwrdprkns Avatar asked Sep 11 '12 23:09

hwrdprkns


People also ask

Where is status bar located?

The status bar is the area at the bottom of the window that contains Help text and coordinate information.

What is my status bar?

Status bar (or notification bar) is an interface element at the top of the screen on Android devices that displays the notification icons, minimized notifications, battery information, device time, and other system status details.

Where is status bar in MS Word?

The Status bar is located at the Bottom of the word window In MS word. The status bar is the area at the bottom of the Word window. It indicates information about the current document. It displays information about what page you are on, as well as your line number on the page and character number on the line.

What is status bar in MS Paint?

A status bar is a graphical control element which poses an information area typically found at the window's bottom. It can be divided into sections to group information. Its job is primarily to display information about the current state of its window, although some status bars have extra functionality.


1 Answers

This is the only method that worked for me. The following method returns the height of the top statusbar. So if the according return value equals 0, there is no statusbar at the top of your window.

public static int getTopStatusBarHeight(Activity activity) {
    Rect rect = new Rect();

    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);

    return rect.top;
}
like image 200
droide_91 Avatar answered Sep 30 '22 17:09

droide_91