获取操作栏,状态栏和导航栏的高度(以像素为单位)

时间:2018-11-11 17:27:05

标签: android

使用下面的Kotlin代码获取操作栏,状态栏和导航栏的高度(以像素为单位)

  /* Height of Action Bar*/
    var mActionBarHeight = 0
    val mAttributes = getTheme().obtainStyledAttributes(
            intArrayOf(android.R.attr.actionBarSize)
    )
    mActionBarHeight = mAttributes.getDimension(0, 0f).toInt()
    mAttributes.recycle()

    /* Height of Status Bar */

    var mStatusBarHeight = 0
    val mResId = resources.getIdentifier("status_bar_height", "dimen", "android")
    if (mResId > 0) {
        mStatusBarHeight = resources.getDimensionPixelSize(mResId)
    }

    /* Height of Navigation Bar */
    var mNavigationBarHeight = 0
    val mResId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
    if (mResId > 0) {
        mNavigationBarHeight = resources.getDimensionPixelSize(mResId)
    }

0 个答案:

没有答案