我有一个页面,其中包含一个操作栏和一个占据页面其余部分的布局 . 我想知道页面其余部分的高度 - 这是SCREEN_HEIGHT - STATUS_BAR_HEIGHT - ACTION_BAR_HEIGHT .
我可以通过platform.screen.mainScreen.heightDIPs获得SCREEN_HEIGHT .
如何获得STATUS_BAR和ACTION_BAR的高度 .
当我尝试做高度或getMeasuredHeight()时,我得到0 .
使用Brad的答案,这是ts代码
let resource_id = application.android.foregroundActivity.getResources().getIdentifier("status_bar_height", "dimen", "android"); if ( resource_id > 0 ) console.log( "status_bar_height=" + application.android.foregroundActivity.getResources().getDimensionPixelSize(resource_id) ); // android.content.res.TypedArray let array = application.android.foregroundActivity.getTheme().obtainStyledAttributes( [ android.R.attr.actionBarSize ] ); console.log( "actionBarHeight=" + array.getDimension(0,0) );
看起来返回的值是实际像素 .
如果你想要DIP值 - 除以platformModule.screen.mainScreen.scale .
1 回答
使用Brad的答案,这是ts代码
看起来返回的值是实际像素 .
如果你想要DIP值 - 除以platformModule.screen.mainScreen.scale .