有没有办法检索应用程序标题和顶栏(包含时钟,信号信息等等)的高度(以像素为单位)。
由于
答案 0 :(得分:3)
创建一个示例android程序。默认情况下,Android会在main.xml中为您创建一个Linearlayout。为该布局提供ID并使用它
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