Android 取得状态栏、任务栏高度的小例子
package com.aslibra.test;
import android.app.activity;
import android.graphics.rect;
import android.os.bundle;
import android.util.log;
import android.view.window;
import android.widget.imageview;
public class test extends activity {
imageview iv;
@override
public void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.main);
iv = (imageview) this.findviewbyid(r.id.imageview01);
iv.post(new runnable()
{
public void run()
{
viewinited();
}
}
);
log.v("test", "== ok ==");
}
private void viewinited(){
rect rect= new rect();
window window= getwindow();
iv.getwindowvisibledisplayframe(rect);
int statusbarheight= rect.top;
int contentviewtop= window.findviewbyid(window.id_android_content).gettop();
int titlebarheight= contentviewtop - statusbarheight;
//测试结果:ok之后 100多 ms 才运行了
log.v("test", "=-init-= statusbarheight="+statusbarheight+
" contentviewtop="+contentviewtop+
" titlebarheight="+titlebarheight);
}
/*
* 07-14 02:36:48.449: verbose/test(1385): == ok ==
* 07-14 02:36:48.558: verbose/test(1385): =-init-= statusbarheight=25 contentviewtop=50 titlebarheight=25
*/
}
浏览器获取状态栏高度的代码
rect visrect = new rect();
if (!mbrowserframelayout.getglobalvisiblerect(visrect)) {
if (logd_enabled) {
log.d(logtag, "showfaketitlebar visrect failed");
}
return;
}
params.y = visrect.top;
上一篇: 微信小程序实现banner图轮播效果
下一篇: 小米手环坏了指示灯不亮该怎么办?