代码之家  ›  专栏  ›  技术社区  ›  jyavenard

如何获取应用程序头的高度?

  •  1
  • jyavenard  · 技术社区  · 14 年前

    是否有方法检索应用程序标题和顶栏(包含时钟、信号信息等)所取的高度(以像素为单位)

    谢谢

    1 回复  |  直到 14 年前
        1
  •  3
  •   DeRagan    14 年前

    final LinearLayout ll1=(LinearLayout)findViewById(R.id.ll1);
    ll1.post(new Runnable()
        {
           public void run()
             {
                Rect rect= new Rect();
                Window window= getWindow(); ll1.getWindowVisibleDisplayFrame(rect);
                int statusBarHeight= rect.top;
                Log.e("", "ht of sb  bar is "+statusBarHeight);
                int contentViewTop= window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
                int titleBarHeight= contentViewTop - statusBarHeight;
                Log.e("", "ht of title bar is "+titleBarHeight);
             }
        }); 
    

    http://andmobidev.blogspot.com/2010/01/getting-height-of-status-and-title-bar.html