【网学网提醒】:本文主要为网学会员提供Android_取得状态栏、任务栏高度,希望对需要Android_取得状态栏、任务栏高度网友有所帮助,学习一下!
(一)代码是参考某位仁兄的片段,以下是可行的完整测试代码:packagecom.aslibra.test;importandroid.app.Activity;importandroid.graphics.Rect;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.Window;importandroid.widget.ImageView;publicclasstestextendsActivity{ImageViewiv;
@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);iv=(ImageView)this.findViewById(R.id.ImageView01);iv.post(newRunnable(){publicvoidrun(){viewInited();}});Log.v("test","==ok==");}privatevoidviewInited(){Rectrect=newRect();Windowwindow=getWindow();iv.getWindowVisibleDisplayFrame(rect);intstatusBarHeight=rect.top;intcontentViewTop=window.findViewById(Window.ID_ANDROID_CONTENT).getTop();inttitleBarHeight=contentViewTop-statusBarHeight;//测试结果:ok之后100多ms才运行了Log.v("test","=-init-=statusBarHeight="+statusBarHeight+"contentViewTop="+contentViewTop+
"titleBarHeight="+titleBarHeight);}
/**07-1402:36:48.449:VERBOSE/test(1385):==ok==*07-1402:36:48.558:VERBOSE/test(1385):=-init-=statusBarHeight=25contentViewTop=50titleBarHeight=25*/}
浏览器获取状态栏高度的代码RectvisRect=newRect();if(!mBrowserFrameLayout.getGlobalVisibleRect(visRect)){if(LOGD_ENABLED){Log.d(LOGTAG,"showFakeTitleBarvisRectfailed");}return;}params.y=visRect.top;
(二)publicstaticintgetScreenHeight(Activityactivity){DrawablephoneCallIcon=activity.getResources().getDrawable(android.R.drawable.stat_sys_phone_call);intnotificationBarHeight=phoneCallIcon.getIntrinsicHeight();intfullScreenHeight=activity.getWindowManager().getDefaultDisplay().getHeight();returnfullScreenHeight-notificationBarHeight;}