状态栏的高度? [英] Height of statusbar?

查看:168
本文介绍了状态栏的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让状态栏+标题栏的高度?检查开发论坛,显示了相同的问题,但没有解决方案(即我能找到)。

我知道我们可以初步布局后传得到它,但我希望得到它的onCreate()我的活动。

感谢

解决方案

 矩形rectgle =新的矩形();
窗口窗口= getWindow();
。window.getDecorView()getWindowVisibleDisplayFrame(rectgle);
INT StatusBarHeight = rectgle.top;
INT contentViewTop =
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
INT TitleBarHeight = contentViewTop  -  StatusBarHeight;

   Log.i(*** Jorgesys ::,状态栏高度=+ StatusBarHeight +,TitleBar中高度=+ TitleBarHeight);
 

获取状态栏的高度在 的onCreate() 您的活动的方法,使用这种方法:

 公众诠释getStatusBarHeight(){
      INT结果为0;
      INT RESOURCEID = getResources()则getIdentifier(status_bar_height,地扪,机器人)。
      如果(RESOURCEID大于0){
          。结果= getResources()getDimensionPixelSize(RESOURCEID);
      }
      返回结果;
}
 

Is there a way to get the height of the statusbar + titlebar? Checking the dev forum shows the same question but no solution (that I could find).

I know we can get it after the initial layout pass, but I'm looking to get it in onCreate() of my activity.

Thanks

解决方案

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;
int contentViewTop= 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int TitleBarHeight= contentViewTop - StatusBarHeight;

   Log.i("*** Jorgesys :: ", "StatusBar Height= " + StatusBarHeight + " , TitleBar Height = " + TitleBarHeight); 

Get the Height of the status bar on the onCreate() method of your Activity, use this method:

public int getStatusBarHeight() { 
      int result = 0;
      int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
      if (resourceId > 0) {
          result = getResources().getDimensionPixelSize(resourceId);
      } 
      return result;
} 

这篇关于状态栏的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆