1.getWindow().getDecorView()获取window最顶层View,该view 通过getWindowVisibleDisPlayFrame()方法获取程序显示的区域 Rect
该view包括标题栏,但是不包括状态栏
2.通过getWindowVisibleDisPlayFrame(rect) 我们可以得到手机状态栏高度
int statusBarHeight = rect.top;
3.getWindow().findViewById(Window.ID_ANDROID_CONTENT);我们可以获得不包括标题栏也不包括状态栏的view;
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleHeight = contentTop - statusBarHeight;
这样就可以计算出标题栏的高度了