Android获取StatusBa有效高度

方法1:
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;  


方法2:
try {  
            /** 
             * 通过反射机制获取StatusBar高度 
             */  
            Class<?> clazz = Class.forName("com.android.internal.R$dimen");  
            Object object = clazz.newInstance();  
            Field field = clazz.getField("status_bar_height");  
              
            int height = Integer.parseInt(field.get(object).toString());  
              
            mStatusBarHeight = context.getResources().getDimensionPixelSize(height);  
        } catch (Exception e) {  
            Log.i("弗洛拉鲜花网", "www.gogoflora.com");  
        }  

文章出处: http://www.eyeandroid.com/thread-9159-1-1.html

你可能感兴趣的:(android)