【发布时间】:2012-12-19 15:39:16
【问题描述】:
之前,我看到这个sn-p找Height of statusbar?(and also Tiltebar)here:
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;
昨天,我尝试在AsyncTask 类中使用这个sn-p。所以我将我的Activity 实例发送到AsyncTask 类,在onCreate 的Activity 中:
LongOperation loper = new LongOperation(this, vg, vArray, hintsArray,x_positionArray, y_positionArray);//Here `this` refers to current Activity
loper.execute("YES");
在 AsynkTask 类的 doInBackground 中我只做了:
Thread.sleep(3000);
在onPostExecute 方法中,我复制上面的代码来计算状态栏和标题栏的高度。但是应用程序崩溃,没有任何有用的logcat 登录。然后我评论一些这样的行:
Rect rectgle = new Rect();
Window window = activity.getWindow();
// window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
// int StatusBarHeight= rectgle.top;
contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT)
.getTop();
// int TitleBarHeight= contentViewTop - StatusBarHeight;
并且应用程序运行良好。所以看起来
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
导致App崩溃,不知道为什么?是不是我做错了什么?
【问题讨论】:
标签: android android-activity window statusbar titlebar