当前位置: 代码迷 >> Android >> 获取排除标题栏与状态栏的View的显示区域高度,该怎么解决
  详细解决方案

获取排除标题栏与状态栏的View的显示区域高度,该怎么解决

热度:74   发布时间:2016-05-01 22:15:50.0
获取排除标题栏与状态栏的View的显示区域高度
int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
网上找了好多方式,基本就是两种个,但是我通过这个方式获取的值都为0,不知道为什么。有人遇到过这个问题吗?

我想做底部的固定按钮区,但是没法获取View显示区域的高度。

我是知道状态栏+标题栏是50px,但是不知道不同的手机上,会不会这个高度有区别,所以得要获取机器的值才行。

有做过底部固定按钮的大侠,帮忙看看。

------解决方案--------------------
public class MainActivity extends Activity {
TextView textView;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
Rect frame = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;


int contentTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
//statusBarHeight是上面所求的状态栏的高度
int titleBarHeight = contentTop - statusBarHeight ;

textView = (TextView)findViewById(R.id.textView1);
textView.setText("状态栏的高度" + Integer.toString(titleBarHeight));
}



}
  相关解决方案